From 3a07cf06c5b77569bc73aa4130f7e78267752bca Mon Sep 17 00:00:00 2001 From: Ruben de Vries Date: Mon, 31 Jul 2017 09:55:39 +0200 Subject: [PATCH] use native .reverse if available --- index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 2ecd6f5..85204d5 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,14 @@ module.exports = function reverse (src) { var buffer = new Buffer(src.length) - for (var i = 0, j = src.length - 1; i <= j; ++i, --j) { - buffer[i] = src[j] - buffer[j] = src[i] - } + if (typeof buffer.reverse === "function") { + return buffer.reverse() + } else { + for (var i = 0, j = src.length - 1; i <= j; ++i, --j) { + buffer[i] = src[j] + buffer[j] = src[i] + } - return buffer + return buffer + } }