Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

First non repeating character position in a string

// First non repeating character position in a string

function first_non_repeating_letter(str) {
  for(var i = 0; i < str.length; i++) {
    if (str.indexOf(str[i]) === str.lastIndexOf(str[i])) {
      return i
    }
  }
  return null
}

console.log("First non repeating character position = " + 
    first_non_repeating_letter("abcdcba"));  //3
 
PREVIOUS NEXT
Tagged: #First #repeating #character #position #string
ADD COMMENT
Topic
Name
2+7 =