Skip to content

Instantly share code, notes, and snippets.

@hamiltondanielb
Last active August 30, 2017 20:11
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 hamiltondanielb/63f2644b199d63f00725abb37b54c7a5 to your computer and use it in GitHub Desktop.
Save hamiltondanielb/63f2644b199d63f00725abb37b54c7a5 to your computer and use it in GitHub Desktop.
Javascript IsUnique String
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