Array.litcoffee

  • fluent-array are methods that extend the Javascript’s Array object@.add (value…)adds a value to the current arrayArray::add = (value…)-> for item in value @.push(item) @
  • @.contains (value)returns true if the current array has valueSuports the case when value is a an Array, where all provided elements of the value array are expected to exists in @Array::contains = (value)-> if value instanceof Array for item in value if not (item in @) return false return true; else (value in @)
  • @.empty ()Array::empty = -> @.length == 0
  • @.item (index)Returns item[index] if array has that itemNote: Double check behaviour of Array.length and check for possible edge casesArray::item = (index)-> if typeof(index) is ‘number’ if @.length > index > -1 return @[index] null
  • @.nth ()Array::nth = Array::item
  • @.first () @.second () @.third () @.fourth ()Helper functions for the nornally requested Array elementsArray::first = -> @.item(0) Array::second = -> @.item(1) Array::third = -> @.item(2) Array::fourth = -> @.item(3)
  • @.last ()Array::last = -> if(@.length) @[@.length-1] else null
  • @.log ()Array::log = -> @.str().log() @
  • @.not_Contains ()Array::not_Contains = (value)-> value not in @
  • @.not_Empty ()Array::not_Empty = -> @.length != 0
  • @.remove_At indexArray::remove_At = (index)-> @.splice(index,1) @
  • @.remove_FirstArray::remove_First = ()-> @.remove_At 0
  • @.remove_If_ContainsRemoves an element from an array if it contains a particular string Note that all elements (and match) will be converted into strings before comparisonArray::remove_If_Contains = (value)-> return @ if not value @.filter (word) -> word.str().not_Contains(value.str())
  • @.sizeArray::size = -> @.length
  • @.starts_With valueArray::starts_With = (value)-> (item for item in @ when value && item.starts_With(value))
  • @.take valueArray::take = (size)-> if size is -1 then @ else @.slice(0,size)
  • @.uniqueArray::unique = () -> output = {} output[@[key]] = @[key] for key in [0…@length] output.keys()
O2 Platform by o2platform