π
(μ½μ΄ μλ°μ€ν¬λ¦½νΈ) 4. μ½λ°±ν¨μ
February 19, 2023
π κΈ°μ μ± μ€ν°λ
23λ
1μλΆν° νλ μ€μΈ κ΅μ‘μμ, λ»μ΄ λ§λ λλ£λ€κ³Ό ν¨κ» μ§ννκ² λ μ€ν°λ
μ²μ μ½μ΄ μλ°μ€ν¬λ¦½νΈ
μμ μ μ½μκ³ μ μνλ©΄μ μμ!
μμΌλ‘λ κΎΈμ€ν κΈ°μ μμ μ μ½κ³ ν¨κ» λ°μ νλ μκ°μ΄ λμμΌλ©΄ μ’κ² λ€!
μ± μ μλ λ΄μ©λ³΄λ¨, μ½μΌλ©΄μ νΌμ μ 리ν λ΄μ©λ€ μμ£Όλ‘ μμ±νμ!
π μ½μ΄ μλ°μ€ν¬λ¦½νΈ 4. μ½λ°±ν¨μ
μΌμ: 2μ 19μΌ 22μ
Quiz1)p101. μμ 4-5. / μ°Έκ³ νμ¬ filter λ©μλ ꡬνν΄λ³΄κΈ°
// μμ 4-5
Array.prototype.map2 = function(callback, thisArg) {
var mappedArr = [];
for (var i = 0; i < this.length; i++) {
var mappedValue = callback.call(thisArg || window, this[i], i, this);
mappedArr[i] = mapppedValue;
}
return mappedArr;
}
μμ λ΅μ
Array.prototype.filter2 = function(callback, thisArg) {
var filteredArr = [];
for (var i = 0; i < this.length; i++) {
var isTrue = callback.call(thisArg || window, this[i], i, this);
if (isTrue) {
filteredArr.push(this[i]);
}
}
return filteredArr;
}
Quiz2)p111. μμ 4-15. / 12~15λ²μ§Έ μ€ μ½λ°± ν¨μ νν λ°κΎΈκΈ°
var addCoffee = function(name) {
return function(prevName) {
return new Promise(function(resolve) {
setTimeout(function() {
var newName = prevName ? (prevName + ', ' + name) : name;
console.log(newName);
resolve(newName);
}, 500);
});
};
};
// μ΄ μλ μ½λλ€
addCoffee('μμ€νλ μ')()
.then(addCoffee('μλ©λ¦¬μΉ΄λ
Έ'))
.then(addCoffee('μΉ΄νλͺ¨μΉ΄'))
.then(addCoffee('μΉ΄νλΌλΌ'))
μμ λ΅μ
addCoffee('μμ€νλ μ')()
.then(prevName => addCoffee('μλ©λ¦¬μΉ΄λ
Έ')(prevName))
.then(prevName => addCoffee('μΉ΄νλͺ¨μΉ΄')(prevName))
.then(prevName => addCoffee('μΉ΄νλΌλΌ')(prevName))
// λΉμ·ν μμ
[1, 2, 3, 4, 5].forEach(console.log)
p113. async/await μ¬μ΄ μμ
async function getDelay(target, second) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(target), second * 1000);
})
}
console.log(await getDelay('λΉλκΈ°', 5)); // 5μ΄ λ€μ 'λΉλκΈ°' μΆλ ₯