문제: 일관된 문자열의 개수 세기
문제 요구사항 (정의)
주어진 문자열 allowed와 문자열 배열 words가 있습니다.
allowed 문자열은 서로 다른 문자들로 이루어져 있습니다.
각 words 배열의 문자열이 allowed에 있는 문자들만 포함하고 있을 때, 그 문자열을 "일관된 문자열"이라고 합니다.
여러분의 목표는 words 배열에서 일관된 문자열의 개수를 세는 것입니다.
function countConsistentStrings(allowed, words) {
// let count = 0;
// words의 인덱스로 순회 돌리기
// allowed의 글자에 배열의 요소의 글자가 include 안 되어있으면 순회 정지
// 모두 include 되어있으면 count++;
// return count;
let count = 0;
for (let i = 0; i < words.length; i++) {
let isInclude = true;
for (let j = 0; j < words[i].length; j++) {
if (!allowed.includes(words[i][j])) {
isInclude = false;
break;
}
}
if (isInclude) {
count++;
}
}
return count;
}