Last active
October 24, 2018 13:07
-
-
Save atikju/89837582341e151a6a1696370f3d6b7e to your computer and use it in GitHub Desktop.
JS - compare two arrays and find the mismatched elements
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
var current = [1, 2, 3, 4, 7, 8], | |
prev = [1, 2, 4], | |
isMatch = false, | |
missing = null; | |
var i = 0, y = 0, | |
lenC = current.length, | |
lenP = prev.length; | |
for ( ; i < lenC; i++ ) { | |
isMatch = false; | |
for ( y = 0; y < lenP; y++ ) { | |
if (current[i] == prev[y]) isMatch = true; | |
} | |
if ( !isMatch ){ | |
missing = current[i]; | |
alert(missing); | |
} // Current[i] isn't in prev | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment