⌈⌋ ⎇ branch:  Bitrhythm


Hex Artifact Content

Artifact bc47a963d78f50df7d2686fdd3be47a4fb9f4cab18db92af0b29fd45eb43a57a:


0000: 2f 2a 2a 0a 20 2a 20 53 70 65 63 69 61 6c 69 7a  /**. * Specializ
0010: 65 64 20 66 75 6e 63 74 69 6f 6e 20 66 6f 72 20  ed function for 
0020: 6c 6f 6f 70 69 6e 67 20 61 6e 20 61 72 72 61 79  looping an array
0030: 2d 6c 69 6b 65 20 63 6f 6c 6c 65 63 74 69 6f 6e  -like collection
0040: 20 77 69 74 68 20 60 65 61 63 68 3d 7b 7d 60 0a   with `each={}`.
0050: 20 2a 20 40 70 61 72 61 6d 20 20 20 7b 20 41 72   * @param   { Ar
0060: 72 61 79 20 7d 20 6c 69 73 74 20 2d 20 63 6f 6c  ray } list - col
0070: 6c 65 63 74 69 6f 6e 20 6f 66 20 69 74 65 6d 73  lection of items
0080: 0a 20 2a 20 40 70 61 72 61 6d 20 20 20 7b 46 75  . * @param   {Fu
0090: 6e 63 74 69 6f 6e 7d 20 66 6e 20 2d 20 63 61 6c  nction} fn - cal
00a0: 6c 62 61 63 6b 20 66 75 6e 63 74 69 6f 6e 0a 20  lback function. 
00b0: 2a 20 40 72 65 74 75 72 6e 73 20 7b 20 41 72 72  * @returns { Arr
00c0: 61 79 20 7d 20 74 68 65 20 61 72 72 61 79 20 6c  ay } the array l
00d0: 6f 6f 70 65 64 0a 20 2a 2f 0a 65 78 70 6f 72 74  ooped. */.export
00e0: 20 64 65 66 61 75 6c 74 20 66 75 6e 63 74 69 6f   default functio
00f0: 6e 20 65 61 63 68 28 6c 69 73 74 2c 20 66 6e 29  n each(list, fn)
0100: 20 7b 0a 20 20 63 6f 6e 73 74 20 6c 65 6e 20 3d   {.  const len =
0110: 20 6c 69 73 74 20 3f 20 6c 69 73 74 2e 6c 65 6e   list ? list.len
0120: 67 74 68 20 3a 20 30 0a 20 20 6c 65 74 20 69 20  gth : 0.  let i 
0130: 3d 20 30 0a 20 20 66 6f 72 20 28 3b 20 69 20 3c  = 0.  for (; i <
0140: 20 6c 65 6e 3b 20 69 2b 2b 29 20 66 6e 28 6c 69   len; i++) fn(li
0150: 73 74 5b 69 5d 2c 20 69 29 0a 20 20 72 65 74 75  st[i], i).  retu
0160: 72 6e 20 6c 69 73 74 0a 7d                       rn list.}