Answers for "find values in an array that repeat 4 times 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

number of repetition in an array javascript

let targetted_array = [3,4,3,23,452,5,3,3,21,1,5,5];  

function countInArray(array, element) {
    let repeat_count = 0;
    for (let i = 0; i < array.length; i++) {
        if (array[i] === element) {
            repeat_count++;
        }
    }
    return repeat_count;
}

countInArray(targetted_array, 3) // will return 4. cuz "3" was repeated 4 times in the targetted_array
countInArray(targetted_array, 5) // will return 3. cuz "5" was repeated 3 times in the targetted_array
Posted by: Guest on January-19-2022

Code answers related to "find values in an array that repeat 4 times javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language