Skip to content

Commit

Permalink
use native .reverse if available
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensayshi committed Jul 31, 2017
1 parent 5e43080 commit 3a07cf0
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 3a07cf0

Please sign in to comment.