(200127_TIL) 'Pangram'
▶ Pangram

(Problem)
Introduction
Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is:
The quick brown fox jumps over the lazy dog.
The alphabet used consists of ASCII letters a to z, inclusive, and is case insensitive. Input will not contain non-ASCII symbols.
- pangram 이란, 알파벳의 모든 철자를 이용한 문장을 말한다.
- 가장 완벽한 English pangram 은 "The quick brown fox jumps over the lazy dog." 이다.
- 알파벳은 a부터 z 까지의 ASCII 문자로 구성되어있고, 굉장히 둔감하다.
- 만약, ASCII 철자에 포함된 것이 아니라면, 아무것도 반환하지 않게 한다.
(Solution)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
// alphabet_array
const alphabet_array = ['a','b','c','d','e','f','g','h','i','j','k','l','m,','n','o','p','q','r','s','t','u','v','w','x','y','z'];
export const isPangram = (string) => {
// convert the given string to lowercase
const lower_string = string.toLowerCase();
// if it is an empty string, it returns false.
if(lower_string == ""){
return false;
}
// check is return value.
let check = true;
// if lower_string is in alphabet_array, change check to false and return.
for(let i=0; i < alphabet_array.length; i++){
if(lower_string.includes(alphabet_array[i]) === false){
check = false;
}
return check
};
};
|
cs |
- alphabet_array 에 모든 알파벳 소문자 철자들을 담은 배열을 정의한다.
- 함수를 통해서 주어지는 string을 toLowerCase()를 통해서, 소문자화시킨다.
[javascript] 대문자, 소문자 변환
toUpperCase()와 toLowerCase()를 사용하면 됩니다. var string='UPPER lower'; string=string.toUpperCase(); console.log(string); //UPPER LOWER string=string.toLowerCase(); console.log(string); //upper l..
squll1.tistory.com
- 빈 값이 주어지면, return으로 false를 반환한다.
- for문을 통해서, alphabet_array에 들어있는 값들이 lower_string (주어진 문자를 소문자화 시킨 변수)에 있는지 확인하기 위해서 includes를 활용했다.
- 만약 if문의 값이 false라면, (알파벳 배열에 없는 요소가 lower_string에 들어있다는 것) return 값으로 반환하는 check 를 false로 변환한다.
developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
Array.prototype.includes() - JavaScript | MDN
includes() 메서드는 배열이 특정 요소를 포함하고 있는지 판별합니다. The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://githu
developer.mozilla.org