Last active
October 15, 2015 22:35
-
-
Save orafaelfragoso/fa6c0818e5fa9e4ed9aa to your computer and use it in GitHub Desktop.
A function to compare two Arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let compareArrays = (arr1, arr2) => { | |
if (!arr1 || !arr2) | |
return false; | |
if (arr1.length !== arr2.length) | |
return false; | |
for(let i=0; i<arr1.length; i++) { | |
if (arr1[i] instanceof Array && arr2[i] instanceof Array) { | |
if (compareArrays(arr1[i], arr2[i])) | |
return false; | |
} else if (arr1[i] != arr2[i]) { | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@raphamorim Obrigado pelo insight! Realmente, usar JSON.stringify é uma gambiarra sagaz mas eu meio que copiei o código do cara lá e adaptei pra minha necessidade, SEM usar prototype!