function emails_for_customers(customers, goods, bests) {
let emails = [];
for_each(customers, function (customer) {
let email = email_for_customer(customer, goods, bests);
emails.push(email);
});
return emails;
}
function emails_for_customers(customers, goods, bests) {
return map(customers, function (customer) {
return email_for_customer(customer, goods, bests);
});
}
function map(array, f) {
let new_array = [];
for_each(array, function (element) {
new_array.push(f(element));
});
return new_array;
}
map()
은 함수형 코딩에서 자주 쓰이는 함수 중 하나이다
X 배열을 Y 배열로 변환하는 역할을 한다