ToyProblem_02_nonrepeatedCharacter
Written on July 19, 2019
문제
Given an arbitrary input string, return the first nonrepeated character in the string. For example:
firstNonRepeatedCharacter(‘ABA’); // => ‘B’ firstNonRepeatedCharacter(‘AACBDB’); // => ‘C’
풀이
var firstNonRepeatedCharacter = function(string) {
for (let i = 1; i < string.length; i++) {
if (string[i] !== string[i - 1]) {
if (!string.slice(i + 1).includes(string[i])) {
return string[i];
}
}
}
};
👩🏻💻 배우는 것을 즐기는 프론트엔드 개발자 입니다
부족한 블로그에 방문해 주셔서 감사합니다 🙇🏻♀️
in the process of becoming the best version of myself