Skip to content

Instantly share code, notes, and snippets.

@thunder775
Created October 25, 2021 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thunder775/00663b370c9f1f9648f2a6ebdd015265 to your computer and use it in GitHub Desktop.
Save thunder775/00663b370c9f1f9648f2a6ebdd015265 to your computer and use it in GitHub Desktop.
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