Removing Duplicated Values in Array using CoffeeScript

Gists

This sample script is for removing duplicated values in array using CoffeeScript.

ar = ["a", "b", "c", "a", "c"]
res = ar.filter (e, i, s) -> s.indexOf(e) is i
console.log res

>>> [ 'a', 'b', 'c' ]

The result which was compiled by CoffeeScript is as follows.

var ar, res;
ar = ["a", "b", "c", "a", "c"];
res = ar.filter(function(e, i, s) {
  return s.indexOf(e) === i;
});
console.log(res);

 Share!