Created
October 25, 2021 10:44
-
-
Save thunder775/00663b370c9f1f9648f2a6ebdd015265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log(firstRepeat("legolas")) | |
console.log(firstRepeat("Gandalf")) | |
console.log(firstRepeat("Balrog")) | |
console.log(firstRepeat("Isildur")) | |
function firstRepeat(str) { | |
const seen = {}; | |
for (let char of str) { | |
if(seen[char]) return char | |
seen[char] = 1 | |
} | |
return -1 | |
} | |
uniqueSort([1, 2, 4, 3])// ➞ [1, 2, 3, 4] | |
uniqueSort([1, 4, 4, 4, 4, 4, 3, 2, 1, 2])// ➞ [1, 2, 3, 4] | |
uniqueSort([6, 7, 3, 2, 1])// ➞ [1, 2, 3, 6, 7] | |
function uniqueSort(arr) { | |
const seen = {} | |
for (let char of arr) { | |
seen[char] = 1 | |
} | |
console.log(Object.keys(seen).map(value => Number(value))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment