From 87a51d4ae0379ee14b70b16ee761bbb2d831b9a5 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Wed, 23 Mar 2016 12:17:24 +0300 Subject: [PATCH] more readable Buffer.compare --- index.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 550c56f..6f85398 100644 --- a/index.js +++ b/index.js @@ -285,17 +285,8 @@ Buffer.compare = function compare (a, b) { var x = a.length var y = b.length - var i = 0 - var len = Math.min(x, y) - while (i < len) { - if (a[i] !== b[i]) break - - ++i - } - - if (i !== len) { - x = a[i] - y = b[i] + for (var i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) return a[i] > b[i] ? 1 : -1 } if (x < y) return -1 -- 2.34.1