I started a course recently and I'm very new at JavaScript. I'm working on a task that requires me to find the first frequency my device reaches twice. I was given 989 numbers, ranging from positves and negatives and I have to find out which number shows up as a multiple frequency first. For example: +3, +3, +4, -2, -4 first reaches 10 twice.
I've tried different variations of code but none give me an output, as if it breaks because of the large amount of numbers. The pastebin for all the numbers I need to imput can be found here: https://pastebin.com/VESwwM2y Using these numbers I have to find which number shows up first, twice. Here's the code I've been using:
function find_duplicate_in_array(arra1) {
var object = {};
var result = [];
arra1.forEach(function (item) {
if(!object[item])
object[item] = 0;
object[item] += 1;
})
for (var prop in object) {
if(object[prop] >= 2) {
result.push(prop);
}
}
return result;
}
console.log(find_duplicate_in_array([]));
I just need to figure out how to get this to work.