title: Can anyone please explain me the following function from eloquent javascript
body: <pre><code>function countBy(items, groupName) {
     let counts = [];
     for (let item of items) {
        let name = groupName(item);
        let known = counts.findIndex(c =&gt; c.name == name);
        if (known == -1) {
           counts.push({
              name,
              count: 1
           });
        } else {
           counts[known].count++;
        }
     }
     return counts;
  }
  
  console.log(countBy([1, 2, 3], n =&gt; n &gt; 2));
  // → [{name: false, count: 2}, {name: true, count: 1}]
  </code></pre>
  
  <p>At the third iteration when item is 3 I would have thought that the value of name is true (which is correct) and known is 0. (because counts = [name = false, count: 2] hence findindex of "name" is 0) but in reality known = -1 . </p>
  
  <p>Can you please explain me why known= -1 (which means that the element is not found, but according to my thinking "name" is found at [name = false, count: 2].)</p>
  
  <p>Many thanks for your thoughts and consideration in advance!!!</p>