Skip to content

Latest commit

Β 

History

History
31 lines (25 loc) Β· 651 Bytes

Higher-Order-Function.md

File metadata and controls

31 lines (25 loc) Β· 651 Bytes

κ³ μ°¨ν•¨μˆ˜

  • ν•¨μˆ˜λ₯Ό κ°’μœΌλ‘œ λ‹€λ£¨λŠ” ν•¨μˆ˜

ν•¨μˆ˜λ₯Ό 인자둜 λ°›μ•„μ„œ μ‹€ν–‰ν•˜λŠ” ν•¨μˆ˜

const apply1 = f => f(1);
const add2 = a => a + 2;

apply1(add2) // 3
apply1(a => a - 1) // 0

const times = (f, n) => {
  let i = - 1;
  while (++i < n) {
    f(i);
  }
}

times(log, 3); 
times(a => a + 10, 3);

=> applicated programing

ν•¨μˆ˜λ₯Ό λ§Œλ“€μ–΄ λ¦¬ν„΄ν•˜λŠ” ν•¨μˆ˜ (ν΄λ‘œμ €λ₯Ό λ§Œλ“€μ–΄ λ¦¬ν„΄ν•˜λŠ” ν•¨μˆ˜)

const addMaker = a => b => a + b; // ν•¨μˆ˜μ΄μž aλ₯Ό κΈ°μ–΅ν•˜λŠ” ν•¨μˆ˜(ν΄λ‘œμ €)
const add10 = addMaker(10);

log(add10) // b => a + b (ν•¨μˆ˜λ₯Ό 리턴)
log(add10(5)) // 15