Answers for "how many times a value is repeated in an array javascript"

0

duplicate an array in javascript n times

const makeRepeated = (arr, repeats) =>
  Array.from({ length: repeats }, () => arr).flat();
  
console.log(makeRepeated([1, 2, 3], 2));
Posted by: Guest on March-26-2021
0

how to count duplicates in an array javascript

arr.reduce((b,c)=>((b[b.findIndex(d=>d.el===c)]||b[b.push({el:c,count:0})-1]).count++,b),[]);
Posted by: Guest on December-16-2020

Code answers related to "how many times a value is repeated in an array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language