Загрузка...

How do you filter out no more than 2 of the same item on a list of multiple items? #javascript

How do you filter out no more than 2 of the same item on a list of multiple items?
#javascripttutorial #coding #filter

***SAMPLE FUNCTION:
function filterList(arr) {
var finalList = [];
return arr.filter(function(n) {
finalList[n] = (finalList[n]||0) + 1;
return finalList[n] **less than or equal to** 2;
});
}
console.log(filterList([1,2,1,2,1,2,2]))
// output: [ 1, 2, 1, 2 ]
console.log(filterList([3,2,5,5,5]))
// output: [ 3, 2, 5, 5 ]
#Shorts #youtubeShorts #trending #viral #quicktips #youtube #youtuber #Shortstiktok

Видео How do you filter out no more than 2 of the same item on a list of multiple items? #javascript канала Let's Code!
Яндекс.Метрика

На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.

Об использовании CookiesПринять