Pages

Nb occurence

Bravo à Tony pour sa réponse !


  1. const test = [1, 1, 3, -12, 5, 3, 16, 2, 1, -13, -12, 5, 1, 2, 1, 3];

  2. const answer = new Map([...test.reduce((map, x) => {
  3.     if (!map.get(x))
  4.         map.set(x, 0);
  5.     map.set(x, map.get(x) + 1);
  6.     return map;
  7. }, new Map()).entries()].sort((a, b) => a[0] - b[0]));


lien