Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
diff arrays
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
You can’t perform that action at this time.