forEach
forEach(x, callback)
Iterates over all elements of a matrix/array, and executes the given callback function.
Try it yourself:
$1 | numberOfPets = {}
| |
$2 | addPet(n) = numberOfPets[n] = (numberOfPets[n] ? numberOfPets[n]:0 ) + 1;
| |
$3 | forEach(["Dog","Cat","Cat"], addPet)
| |
$4 | numberOfPets
|