Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. //find if string has unique chars...
  2. Object.assign(String.prototype, {
  3. HasUniqueChars(){
  4. for(let i =0; i < this.length; i++){
  5. for(let j =i+1; j < this.length; j++){
  6. if(this[i] == this[j])
  7. return false;
  8. }
  9. }
  10. return true;
  11. }
  12. });
  13.  
  14.  
  15. console.log("abcd".HasUniqueChars()); // true
  16.  
  17. console.log("abccd".HasUniqueChars()); // false
  18.  
  19. //Big(O) = n*n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement