π μ€λ λ νμκΉ?
- μ€μ μ repl.it λͺ»νκ±° λ§μ νλ€
- μ€νμ
λ°±μλ
μ λν΄ μμΈν μ€λͺ
ν΄μ£Όμ
¨λλ° νλ‘ νΈ
κ° λ μ’μμ‘λ€.
- λ¨μ μκ° CSS λ μ΄μμ μ΄ν΄ μκ°λ λΆλΆ 볡μ΅!
π³ μ€λ λ κ³΅λΆ νμκΉ?
1. μΆκ°λ String λ©μλ
const email = 'abc@gmail.com';
console.log(email.starstWith('ab'));
console.log(email.endsWith('com'));
console.log(email.includes('mail'));
startsWith
: μ΄λ€ νΉμ λ¬Έμλ‘ μμνλμ§
endsWith
: μ΄λ€ νΉμ λ¬Έμλ‘ λλλμ§
includes
: μ΄λ€ νΉμ ν¬ν¨νλμ§
2. map λ©μλ νμ©
const formatDate = dates => {
const answer = dates.map(date => {
const dateArr = date.split('-');
const result = dateArr.map((date,index)=>{
if(index === 0)
return date + 'λ
';
else if(index === 1)
return date + 'μ';
else
return date + 'μΌ';
}).join(' ');
return result;
});
console.log(answer);
return answer;
}
- YYYY-MM-DD νμ
μ YYYYλ
MMμ DDμΌλ‘ λ³κ²½νλ λ¬Έμ
- λ¬Έμμ΄
date
λ₯Ό split
λ©μλλ‘ λ°°μ΄ ννλ‘ λ³κ²½
map
λ©μλλ‘ λ°°μ΄μ λλ©° -
λ¬Έμλ₯Ό μ°Ύκ³ μμλλ‘ λ
, μ
, μΌ
λ‘ λ°κΏ
- λ°°μ΄ μνμ΄ λλλ©΄
join
λ©μλλ‘ κ³΅λ°±λ¬Έμ ꡬλΆμλ₯Ό μΆκ°νμ¬ λ¬Έμμ΄λ‘ λ³κ²½
- λ³κ²½λ λ¬Έμμ΄μ λ°ννμ¬ κΈ°μ‘΄ λ¬Έμμ΄κ³Ό λ³κ²½
3. κ°μ²΄ π λ°°μ΄ λ³ν
const myObj = {
one: "1",
two: "2",
};
console.log(Object.keys(myObj));
console.log(Object.values(myObj));
console.log(Object.entries(myObj));
Object.keys()
λ©μλλ κ°μ²΄μ keyλ₯Ό λ°°μ΄λ‘ λ°ν
Object.values()
λ©μλλ κ°μ²΄μ valueλ₯Ό λ°°μ΄λ‘ λ°ν
Object.entries()
λ©μλλ κ°μ²΄μ key, valueλ₯Ό ν¨κ» μ΄μ°¨μ λ°°μ΄λ‘ λ°ν
4. κ°μ²΄, λ°°μ΄μ νμ©ν μ±μ ν λ¬Έμ
const scores = {
μνμμνκ³: "C",
λ
Όλ¦¬μ κΈμ°κΈ°: "B",
λ
μΌλ¬Ένμμ΄ν΄: "B+",
κΈ°μ΄μν: "D+",
μΈμ§μ¬λ¦¬ν: "A+",
};
const charScores = Object.values(scores);
const pointScores = charScores.map((score) => {
if (score === "A+") return 4.5;
else if (score === "A") return 4;
else if (score === "B+") return 3.5;
else if (score === "B") return 3;
else if (score === "C+") return 2.5;
else if (score === "C") return 2;
else if (score === "D+") return 1.5;
else return 1;
});
let index = 0;
for (const key in scores) {
scores[key] = pointScores[index];
index++;
}
const subjects = Object.keys(scores);
const requireClass = ["μμ΄νν", "κΈ°μ΄μν", "곡νμν", "μ»΄ν¨ν°κ³Όνκ°λ‘ "];
const filterClass = requireClass
.map((subject) => {
if (subjects.indexOf(subject) === -1) return subject;
else return 0;
})
.filter((subject) => subject !== 0);
filterClass.forEach((subject) => (scores[subject] = 0));
λ¬Έμν
μ±μ μ μ«μν
μΌλ‘ λ³ννλ λ¬Έμ
scores
κ°μ²΄μμ λ¬Έμν
μ μλ§ μΆμΆν΄ μ«μν
μΌλ‘ λ³κ²½
scores
κ°μ²΄λ₯Ό μννλ©° μ«μνμΌλ‘ κ°μ λ³κ²½
scores
κ°μ²΄μμ key
λ§ λ°°μ΄λ‘ μΆμΆν΄ requireClass
λ°°μ΄κ³Ό λΉκ΅ ν μλ κ³Όλͺ©λ§ νν°λ§
- νν°λ λλ¨Έμ§ κ³Όλͺ©λ€μ
scores
κ°μ²΄μ value
λ 0μΌλ‘ μΆκ°