Last active
August 30, 2017 20:11
-
-
Save hamiltondanielb/63f2644b199d63f00725abb37b54c7a5 to your computer and use it in GitHub Desktop.
Javascript IsUnique String
This file contains hidden or 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
function isUnique( s ) { | |
var chars = {} | |
var dup = true; | |
for (var i = 0; i < s.length; ++i) { | |
if ((s[i] in chars)) { | |
return false; | |
} | |
chars[s[i]] = 1; | |
} | |
return dup; | |
} | |
console.log(isUnique("abc")); // true | |
console.log(isUnique("abcb")); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment