list1 = ["green", "red", "blue", "red"]
list2 = ["green", "yellow", "red"]
# 独立した関数を定義する場合
diff = (list1, list2)-> (value for value in list1 when list2.indexOf(value) is -1)
# prototypeを拡張する場合
Array::diff = (array)-> (value for value in this when array.indexOf(value) is -1)
console.log diff(list1, list2)
console.log list1.diff(list2)
IE8以下対応は Array.prototype.indexOf
を定義しないとだめ http://qiita.com/suin/items/f08af948279f87d84865#1-1
Array::indexOf or= (item) ->
for x, i in this
return i if x is item
return -1