π Day 7 Algorithm Review

j00b33Β·2022λ 3μ 22μΌ
0

8/12

π Replit

str.split(", ")

const handleEdit = (nickname, interests) => {
const handleObj = {
nickname: nickname,
interests: interests.split(', '),
bio: μ  λλ€μμ ${nickname}μ λλ€. μ·¨λ―Έλ${interests.split(', ')}μλλ€.
}
return handleObj
}

// {
//  nickname: 'λλΉ',
//  bio: 'μ  λλ€μμ λλΉμλλ€. μ·¨λ―Έλ λ°©νμΆ,νλμ€,λ© λλ¦¬κΈ°μλλ€.'
// }

str.trim()

const example = " asdf asdf "
example.trim() // Remove both first and last indent
example.trimStart()	// Remove first indent
example.trimEnd() // Remove last indent

π Class

isNaN vs. Number.isNaN

// isNaN
// 1. ν΄λΉ λ°μ΄ν°κ° NaN κ°μ κ°μ§λμ§ νλ¨
// 2. μΆλ ₯κ°μ΄ falseμΌ λλ μ«μκ° λ§λ€. trueμΌ λλ NaNκ°μ κ°μ§λ€

isNaN("a")	//true
isNaN("10")	//false

// Number.isNaN
// 1. ν΄λΉ λ°μ΄ν°κ° Number νμμ΄λ©΄μ NaN κ°μ΄ λ§λμ§λ₯Ό κ²μ¦
// 2. NaN κ²μ¦μ μ’ λ μκ²©νκ² μ§ν

isNaN("0/0")	//true
Number.isNaN("0/0")	//false

isNaN(undefined) //true
Number.isNaN(undefined) //false

π λ¬Έμμ΄ λ€λ£¨κΈ° κΈ°λ³Έ

function solution(s){
if (s.length !== 4 && s.length !== 6){
return false
}

const answer = s.split("").filter(num => {
// λ¬Έμκ° λ§λ λ°μ΄ν°λ§ λ¨κΈ°κΈ°
return isNaN(num)
})

// λ°°μ΄μ΄ λΉμ΄μλμ§ (μ¦ λ¬Έμμ΄μ΄ νλλΌλ μ‘΄μ¬νλμ§)λ₯Ό νλ¨ν΄μ
}

solution("a234") //false
solution("8ys2") //false
solution("1234") //true

function solution(n){
for (let i = 1; i<=n; i++){
if (n%i===0){
}
}
}
//reduce method μ¬μ©
function solution(n){
.reduce((acc, cur, i) => {

return n%(cur+i)===0
? acc + (cur + i)
: acc
},0)

}

solution(12) // 28
solution(5)  // 6
λλΉλλ°₯λ°₯