const ITEM_COUNT = 100
let visibleItems = []
for (let i = 0; i < ITEM_COUNT; ++i) {
  visibleItems.push(false)
}

function showItem(index) {
  visibleItems = []
  for (let i = 0; i < ITEM_COUNT; ++i) {
    visibleItems.push(false)
  }
  visibleItems[index] = true
}

It was more or less like this. The guy had a collection of React components and wanted to show only one of them at a time. Instead of storing the index of the component to show at the moment, he decided that a boolean array would work much better. O(n) in runtime and space and null readability just because.

By Anonymous, 2019-12-07 11:59:58