Created
January 19, 2013 18:10
-
-
Save knalli/4574041 to your computer and use it in GitHub Desktop.
NodeUnit equalArrayitems
This file contains 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
equalArrayItems = (actual, expected) -> | |
test.ok actual instanceof Array | |
test.ok expected instanceof Array | |
test.equals actual.length, expected.length | |
# Loop 1: All values of "expected" MUST be in "actual". | |
for item in expected | |
test.ok actual.indexOf(item) > -1 | |
# Loop 2: All values of "actual" MUST be in "expected". | |
for item in actual | |
test.ok expected.indexOf(item) > -1 | |
equalArrayItems array1, array2 |
This file contains 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
equalArrayItems = (actual, expected) -> | |
return false unless actual instanceof Array | |
return false unless expected instanceof Array | |
return false if actual.length isnt expected.length | |
# Loop 1: All values of "expected" MUST be in "actual". | |
return false if (item for item in expected when actual.indexOf(item) > -1).length isnt expected.length | |
# Loop 2: All values of "actual" MUST be in "expected". | |
return false if (item for item in actual when expected.indexOf(item) > -1).length isnt actual.length | |
true | |
test.ok equalArrayItems array1, array2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment