https://www.codewars.com/kata/54ba84be607a92aa900000f1
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case.
Example: (Input --> Output)
"Dermatoglyphics" --> true "aba" --> false "moOse" --> false (ignore letter case)
설명:
아이서그램(Isogram)은 연속적이거나 비연속적이거나 반복되는 문자를 가지고 있지 않은 단어입니다. 오직 문자로만 구성된 문자열이 아이서그램인지 아닌지 결정하는 함수를 구현하세요. 빈 문자열은 아이서그램이라고 가정합니다. 대소문자는 무시합니다.
예시: (입력 --> 출력)
"Dermatoglyphics" --> true "aba" --> false "moOse" --> false (대소문자는 무시)
풀이
set으로 중복이 없는 배열을 만들고 입력받은 문자열의 길이가 set으로 만든 배열의 길이와 다르면 false 같으면 true를 반환했다.
코드
function isIsogram(str){
str = str.toLowerCase();
let set = [...new Set(str)];
if(str.length !== set.length) return false;
return true;
}
참고
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Set
Set - JavaScript | MDN
Set 객체는 자료형에 관계 없이 원시 값과 객체 참조 모두 유일한 값을 저장할 수 있습니다.
developer.mozilla.org
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Mumbling (7 kyu) / JavaScript (0) | 2022.10.28 |
---|---|
[Codewars] Highest and Lowest (7 kyu) / JavaScript (0) | 2022.10.27 |
[Codewars] Square(n) Sum (8 kyu) / JavaScript (0) | 2022.10.26 |
[Codewars] MakeUpperCase (8 kyu) / JavaScript (0) | 2022.10.26 |
[Codewars] Grasshopper - Personalized Message (8 kyu) / JavaScript (0) | 2022.10.26 |
댓글