Skip to content

Instantly share code, notes, and snippets.

@fatihacet
Created March 22, 2014 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fatihacet/9703650 to your computer and use it in GitHub Desktop.
Save fatihacet/9703650 to your computer and use it in GitHub Desktop.
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