Created
August 3, 2021 23:00
-
-
Save z7pz/d3d36a89d0847915bca55e27c3ba6f7f to your computer and use it in GitHub Desktop.
first non repeating char
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
// default: 5.187ms (nevermind) | |
function f(s) { | |
let arr = Array.apply(0, { length: 26 }).map((c) => 0) | |
for (let c of s.split('')) arr[c.charCodeAt(0) - 'a'.charCodeAt(0)]++; | |
for (let c of s.split('')) { | |
if (arr[c.charCodeAt(0) - 'a'.charCodeAt(0)] == 1) return c; | |
} | |
console.log(arr) | |
return '_' | |
} | |
console.log( | |
f('') | |
); | |
// default: 10.70ms (Tarek Hesham#0001) | |
const char = (str) => { | |
for (let i = 0; i < str.length; i++) { | |
if (str.split("").filter(x => x == str[i]).length == 1) return str[i]; | |
}; | |
}; | |
console.log(char("")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment