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/3072042c725c82f79116dc23ccd5e3f6 to your computer and use it in GitHub Desktop.

Select an option

Save lienista/3072042c725c82f79116dc23ccd5e3f6 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) => {
for(let i=0;i<str.length; i++) {
for(let j=i+1;j<str.length; j++) {
if(str[i] === str[j])
return false;
}
}
return true;
}
const s = 'Geeks for Geeks';
const y = stringHasUniqueChars(s);
const x = 'abc';
const 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