yasuoza diary

web and life

Array#compact in CoffeeScript

1
2
3
4
5
6
7
8
Array::compact = ->
  (elem for elem in this when elem?)

arr = [0..10]
delete arr[7]
delete arr[8]

console.log arr.compact() #=> [0, 1, 2, 3, 4, 5, 6, 9, 10]

Yeah!

Comments