Skip to content

Latest commit

 

History

History
38 lines (25 loc) · 925 Bytes

detect.md

File metadata and controls

38 lines (25 loc) · 925 Bytes

detect

Detect is a simplified version of find.

detect [ 1, 2, 3 ]
  (elt % 2) == 0
# f.ret --> 2

With objects (maps), it returns the first matching entry (pair).

detect { a: 'A', b: 'B', c: 'C' }
  val == 'B'
# f.ret --> [ 'b', 'B' ]

iterating blocks

Iterating blocks are given 3 to 4 local variables.

A block iterating over an array will receive elt (the current element of the iteration), idx (the zero-based index of the current element), and len (the length of the array).

A block iterating over an object will receive key (the current string key), val (the current value), idx (the zero-based index of the current key/val), and len (the length of the object).

see also

find.