Count Ones in a 2D Array

Published by Helen Yu in

Create a function to count the number of 1s in a 2D array.

Examples

countOnes([
  [1, 0],
  [0, 0]
]) ➞ 1

countOnes([
  [1, 1, 1],
  [0, 0, 1],
  [1, 1, 1]
]) ➞ 7

countOnes([
  [1, 2, 3],
  [0, 2, 1],
  [5, 7, 33]
]) ➞ 2

Notes

N/A

Watch a quick demo on how Edabit works.