Created
March 22, 2014 09:16
-
-
Save fatihacet/9703650 to your computer and use it in GitHub Desktop.
diff arrays
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
console.clear() | |
diff = (a, b) -> | |
deleted = [] | |
added = [] | |
# deleted.push item for item in a when b.indexOf(item) is -1 | |
# added.push item for item in b when a.indexOf(item) is -1 | |
clone = b.slice 0 | |
for item, index in a | |
if b.indexOf(item) is -1 | |
deleted.push item | |
clone.splice item, 1 | |
added = clone | |
console.log "added: #{added} deleted: #{deleted}" | |
diff [1, 2, 3, 4, 5, 6], [0, 12, 1, 4, 7, 8, 9, 10] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment