Skip to content

Instantly share code, notes, and snippets.

@lienista
Last active August 28, 2018 07:44
Show Gist options
  • Select an option

  • Save lienista/9d2181a1b5da81823221137126a9d6e4 to your computer and use it in GitHub Desktop.

Select an option

Save lienista/9d2181a1b5da81823221137126a9d6e4 to your computer and use it in GitHub Desktop.
Algorithms in Javascript: CTCI 1.1 - Is Unique: Write a function to determine if a string has all unique characters.
const stringHasUniqueChars = (str) => {
str.split('').sort().join('');
for(let i=0;i<str.length; i++) {
if(str[i] === str[i+1]) {
return false;
}
}
return true;
}
let s = 'Geeks for Geeks';
let y = stringHasUniqueChars(s);
let x = 'abc';
let z = stringHasUniqueChars(x);
console.log(s + ': ' + y);
console.log(x + ': ' + z);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment