repeat

Run Settings
LanguageJavaScript
Language Version
Run Command
//Google Question //Given an array = [2,5,1,2,3,5,1,2,4]: //It should return 2 //Given an array = [2,1,1,2,3,5,1,2,4]: //It should return 1 //Given an array = [2,3,4,5]: //It should return undefined function firstRecurringCharacter(input){ rep = {}; for(let i=0;i<input.length;i++){ // console.log(rep); if(rep[input[i]]){ return input[i]; } else if(!rep[input[i]]){ rep[input[i]]=true; } } return undefined; } array = [2,3,4,5,2] // firstRecurringCharacter(array) console.log(firstRecurringCharacter(array)); //Bonus... What if we had this: // [2,5,5,2,3,5,1,2,4] // return 5 because the pairs are before 2,2
Editor Settings
Theme
Key bindings
Full width
Lines