Introduction to Javascript Algorithm Problem Solving (Coding Test Preparation)
17. Remove duplicate words
다음과 같이 풀어도 무방할까요?
Written on
·
137
1
function solution(s) {
let answer= [];
for (let x of s) {
if (answer.indexOf(x) === -1) {
answer += x+'\n';
}
}
return answer;
}
let str = ["good", "time", "good", "time", "student"];
console.log(solution(str));