DevYoon
[ํ๋ก๊ทธ๋๋จธ์ค] ์์ฃผํ์ง ๋ชปํ ์ ์ (JavaScript) ๋ณธ๋ฌธ
PS/Programmers
[ํ๋ก๊ทธ๋๋จธ์ค] ์์ฃผํ์ง ๋ชปํ ์ ์ (JavaScript)
gimewn 2022. 8. 26. 00:14link ๐ https://school.programmers.co.kr/learn/courses/30/lessons/42576?language=javascript
๐ ํจ์จ์ฑ ํ ์คํธ ํต๊ณผ ๋ชปํ ์ฝ๋
function solution(participant, completion) {
var answer = "";
participant.map((word)=>{
if(completion.includes(word)){
let where = completion.indexOf(word)
completion.splice(where, 1)
}else{
answer = word;
}
});
return answer;
}
๐ ํจ์จ์ฑ๊น์ง ํต๊ณผํ ์ฝ๋
function solution(participant, completion) {
var answer = "";
let isComple = {};
participant.map((word)=>{
if(word in isComple){
isComple[word] += 1
}else{
isComple[word] = 1
}
})
completion.map((word)=>{
isComple[word] -= 1
})
let keys = Object.keys(isComple)
keys.map((word)=>{
if(isComple[word] === 1){
answer = word;
}
})
return answer;
}