문제
N개의 문자열이 입력되면 중복된 문자열은 제거하고 출력
풀이 과정 a
const solutionA = (words) => {
const answer = [];
for (let i = 0; i < words.length; i++) {
const word = words[i];
if (words.indexOf(word) === i) answer.push(word);
}
return answer;
};
const testA = solutionA(['good', 'time', 'good', 'time', 'student']);
console.log(testA);
풀이 과정 b
const solutionB = (words) => {
const answer = words.filter((word, index) => words.indexOf(word) === index);
return answer;
};
const testB = solutionB(['good', 'time', 'good', 'time', 'student']);
console.log(testB);
틀린 부분이 있거나 보충해야 할 내용이 있다면 댓글이나 DM(sungstonemin)으로 알려주시면 감사하겠습니다😄