Javascript String Question 12

Introduction

Create a method that will determine if a string has all unique characters.

Do not create an data structure to do this.

 AnswerCode:
                                                                                              
 function unique(string) {
   //your code/*from  w  w w . ja  v  a  2s .com*/
 }
                                                                                              
 console.log(unique(string));
                                                                                              
 var string = 'ccatt';
                                                                                              
 function unique(string) {
   var letter = string[0];
   for(var i = 1; i< string.length; i++) {
     if(letter == string[i]) {
       return false;
     }
     letter = string[i];
   }
   return true;
 }
                                                                                              
 console.log(unique(string));



PreviousNext

Related