Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

first unique character in a string javascript

var firstUniqChar = function(s) {

    for(let i = 0; i < s.length; i++) {
       if( s.indexOf( s.substring(i, i + 1) ) === s.lastIndexOf( s.substring(i, i + 1) ) ) {
           return i
       }
   }

   return -1

};
Comment

first unique character in a string javascript

var firstUniqChar = function(s) {

    const letterCounter = {}

  for(const letter of s) {
    if(letterCounter[letter]) letterCounter[letter]++
    else letterCounter[letter] = 1
  }

  for( let i = 0; i < s.length; i++) {
    const stringLetter = s[i]

    if (letterCounter[stringLetter] === 1) {
        return i
    }
  }

  return -1

};
Comment

first unique character in a string javascript

var firstUniqChar = function(s) {

   for( let i = 0; i < s.length; i++) {
       const letter = s[i]

       if(s.indexOf(letter) === s.lastIndexOf(letter)) {
           return i
       }
   }

    return -1

};
Comment

PREVIOUS NEXT
Code Example
Javascript :: node api return file 
Javascript :: how to get value of tinymce in javascript 
Javascript :: can we add two functions onclick event 
Javascript :: react native refresh control color 
Javascript :: how to include a toasted property in vue 
Javascript :: arrow functions javascript 
Javascript :: what is prototype javascript 
Javascript :: how to detect input value change by javascript observe 
Javascript :: nested model in angular 
Javascript :: pandas json_normalize column with json array 
Javascript :: function expression javascript 
Javascript :: useQuery by click 
Javascript :: formula regex para validar cpf e cnpj no google forms 
Javascript :: good way to check object properties in js 
Javascript :: hide and open jquery 
Javascript :: vue route automatic redirect 
Javascript :: filter data from object 
Javascript :: homepage field in package.json 
Javascript :: jquery deferred 
Javascript :: remove last tag in dom javascript 
Javascript :: angular singleton service example 
Javascript :: GET and CHANGE the class of an element 
Javascript :: javascript eval() function 
Javascript :: react native ant design 
Javascript :: Create Dark And Light Mode Website Using jQuery 
Javascript :: openstreetmap api example javascript 
Javascript :: loop over a nerber in react 
Javascript :: javascript get first element of array 
Javascript :: get last element in array javascript 
Javascript :: push array into array javascript 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =