Find longest occurrence of same number in array

前端 未结 12 1531
一生所求
一生所求 2021-01-05 17:49

Using JavaScript, I\'m trying to find a way to find the longest occurrence of the same number (in this case, 1) in an array.

For instance, here\'s a sample array:

12条回答
  •  佛祖请我去吃肉
    2021-01-05 18:12

    Alternative: use regexp and converting the array to a string.

    var arr = [2,5,3,1,1,1,3,7,9,6,4,1,1,1,1,1,4,7,2,3,1,1,4,3];
    var str = arr.join('').match(/1+/g);
    console.log(process ? process.sort().pop() : "No ocurrences");
    

提交回复
热议问题