Find the unique string ( 5 kyu )
문제
There is an array of strings. All strings contains similar letters except one. Try to find it!
findUniq([ 'Aa', 'aaa', 'aaaaa', 'BbBb', 'Aaaa', 'AaAaAa', 'a' ]) === 'BbBb'
findUniq([ 'abc', 'acb', 'bac', 'foo', 'bca', 'cab', 'cba' ]) === 'foo'
Strings may contain spaces. Spaces is not significant, only non-spaces symbols matters. E.g. string that contains only spaces is like empty string.
It’s guaranteed that array contains more than 3 strings.
배열중 다른 알파벳으로 구성된 단어를 찾는 문제
풀이
function findUniq(arr) {
let newArr = arr.map(a => { return [...new Set(a.toLowerCase())].sort().join('') });
for ( let i = 0; i < newArr.length; i++ ) {
if ( newArr.indexOf(newArr[i]) === newArr.lastIndexOf(newArr[i]) ) return arr[i]
}
}
Set으로 중복을 제거 후에, indexOf로 유일한 값을 찾아 리턴
다른 사람의 풀이
별로임