Created
October 13, 2013 17:34
-
-
Save mcsheffrey/6964981 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findObjPropInArr(arr, prop, val) { | |
for(var i = 0; i<arr.length; i++) { | |
if(arr[i][prop] === val) { | |
return i; | |
} | |
} | |
return -1; | |
} | |
function findFirstNoRepeat(word) { | |
var wordCount = [], | |
arrIndex, | |
i, | |
r; | |
for(i = 0; i<word.length; i++) { | |
arrIndex = findObjPropInArr(wordCount, 'letter', word.charAt(i)); | |
if (arrIndex > -1) { | |
wordCount[arrIndex].count++; | |
} else { | |
wordCount.push({ | |
letter: word.charAt(i), | |
count: 1 | |
}); | |
} | |
} | |
console.log(wordCount); | |
for(r = 0; r<wordCount.length; r++) { | |
if(wordCount[r].count === 1) { | |
console.log(wordCount[r].letter) | |
return wordCount[r].letter | |
} | |
} | |
} | |
findFirstNoRepeat('teeter'); | |
findFirstNoRepeat('total'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment