From fc1c9162d69372a6e703d6b5fd95996c070d24a3 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sat, 7 May 2022 16:53:04 +0200 Subject: [PATCH] chore: factor out `Array.equals` Signed-off-by: Matej Focko --- avl.js | 16 ---------------- index.html | 2 ++ utils.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 utils.js diff --git a/avl.js b/avl.js index dc26499..b618142 100644 --- a/avl.js +++ b/avl.js @@ -1,19 +1,3 @@ -// TODO: Factor out to common module -Array.prototype.equals = function (other) { - if (this.length != other.length) { - return false; - } - - let i = this.length; - while (--i >= 0) { - if (this[i] !== other[i]) { - return false; - } - } - - return true; -}; - function balanceFactor(node) { if (!node) { return 0; diff --git a/index.html b/index.html index caa227f..0e83754 100755 --- a/index.html +++ b/index.html @@ -40,6 +40,8 @@ + + diff --git a/utils.js b/utils.js new file mode 100644 index 0000000..120f869 --- /dev/null +++ b/utils.js @@ -0,0 +1,14 @@ +Array.prototype.equals = function (other) { + if (this.length != other.length) { + return false; + } + + let i = this.length; + while (--i >= 0) { + if (this[i] !== other[i]) { + return false; + } + } + + return true; +};