first recurring

Run Settings
LanguageJavaScript
Language Version
Run Command
let arr1 = [2,5,1,2,3,5,1,2,4]; let arr2 = [2,1,1,2,3,5,1,2,4]; let arr3 = [2,3,4,5]; let arr4 = [2,5,5,2,3,5,1,2,4]; //It should return 1 function firstRecurring(arr) { let hash = []; for(let i of arr) { if(!hash[i]) hash[i] = [i,0]; else return i; } } console.log(firstRecurring(arr1)); console.log(firstRecurring(arr2)); console.log(firstRecurring(arr3)); console.log(firstRecurring(arr4));
Editor Settings
Theme
Key bindings
Full width
Lines