From 540681b2bc220d5dcc496bd453c82c2a5fe25c1d Mon Sep 17 00:00:00 2001 From: Devin Weaver Date: Fri, 25 Apr 2014 08:42:45 -0400 Subject: [PATCH] Add $tw.util.isEqual This checks to see if an array is equal. Should handle case where an array is considered null or undefined. It short circuits when the lengths are different and will only loop when needed. --- boot/boot.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/boot/boot.js b/boot/boot.js index 658f8e980..b02e2380f 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -85,6 +85,18 @@ $tw.utils.each = function(object,callback) { } }; +/* +Check if an array is equal by value and by reference. +*/ +$tw.utils.isEqual = function(array1,array2) { + if(array1 === array2) { return true; } + array1 = array1 || []; array2 = array2 || []; + if(array1.length !== array2.length) { return false; } + return array1.every(function(value,index) { + return value === array2[index]; + }); +}; + /* Helper for making DOM elements tag: tag name