N-Repeated Element in Size 2N Array LeetCode solution in JavaScript

1
var repeatedNTimes = function (nums) {
2
// loop through the array and then as we go over every num we filter that number and get the length. If the length is equal to 1 that is not the element so we continue if its not equal to one its the element we want and we just return that element.
3

4
for (let num of nums) {
5
let len = nums.filter((element) => element === num).length;
6
if (len == 1) continue;
7
else return num;
8
}
9
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0