π¨βπ»Β μ¬κ±΄
- 2μ€ for λ¬ΈμΌλ‘ λλ €μ, κ° μ€λ³΅μμκ° λͺλ² μΉ΄μ΄νΈκ° λμλμ§λ₯Ό 체ν¬ν μκ°μ΄μλ€. ( Set μ체λ μ€λ³΅ μμλ₯Ό μ κ±° )
let νμ¬κ²μν = ['ν‘','ν‘','ν‘','ν‘','ν‘','λ ¬','λ ¬','λ ¬','λ','λ','λ']
let newcom = new Set(νμ¬κ²μν)
let cnt=0
for (const i of newcom){
for(const j of νμ¬κ²μν){
if(i===j){
cnt++;
}
}
console.log(i,cnt)
cnt=0
}
β
Β ν΄κ²°
- filter λ₯Ό νμ©νμ¬ κ°λ¨νκ² λ¬Έμ ν΄κ²°μ΄ κ°λ₯νμλ€.
let νμ¬κ²μν = ['ν‘','ν‘','ν‘','ν‘','ν‘','λ ¬','λ ¬','λ ¬','λ','λ','λ']
let newcom = new Set(νμ¬κ²μν)
for (const i of newcom){
console.log(i, νμ¬κ²μν.filter(e=>e===i).length)
}
πΒ κ°μ
- νμν λ©μλλ₯Ό μΆ©λΆν μΈμ§νκ³ μμ΄μΌ κ² λ€.