JavaScript

JavaScript ๋ฐฐ์—ด ๊ณ ์ฐจ ํ•จ์ˆ˜(Higher-Order Function)

kohi โ˜• 2022. 10. 13. 14:49

๐Ÿ” ๊ณ ์ฐจ ํ•จ์ˆ˜์˜ ๊ธฐ๋ณธ ์ •์˜


  • ๊ณ ์ฐจ ํ•จ์ˆ˜๋ž€ ํ•จ์ˆ˜๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์ „๋‹ฌ ๋ฐ›๊ฑฐ๋‚˜ ์—ฐ์‚ฐ์˜ ๊ฒฐ๊ณผ๋กœ ๋ฐ˜ํ™˜ํ•ด ์ฃผ๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ๋งํ•œ๋‹ค.
  • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ์— ์•Œ๋งž์€ ์–ธ์–ด๋กœ ๋งŒ๋“ค์–ด ์ฃผ๋Š” ํŠน์„ฑ์ด๋‹ค.
  • ๊ณ ์ฐจ ํ•จ์ˆ˜์˜ ๊ฐœ๋…์„ ์™„์ „ํžˆ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ๊ณผ ํผ์ŠคํŠธ ํด๋ž˜์Šค ํ•จ์ˆ˜์˜ ๊ฐœ๋…์„ ์ดํ•ดํ•˜๋Š” ๊ฒƒ์ด ์„ ํ–‰๋˜์–ด์•ผ ํ•œ๋‹ค.

 

ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ

ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ์€ ํ•จ์ˆ˜๋ฅผ ๋‹ค๋ฅธ ํ•จ์ˆ˜์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„˜๊ธธ ์ˆ˜๋„ ์žˆ๊ณ  ๋ฆฌํ„ด ๊ฐ’์œผ๋กœ ํ•จ์ˆ˜๋ฅผ ๋ฐ›์„ ์ˆ˜๋„ ์žˆ๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํ˜•ํƒœ์ด๋‹ค. ์ˆœ์ˆ˜ ํ•จ์ˆ˜ + ๋ณด์กฐ ํ•จ์ˆ˜์˜ ์กฐํ•ฉ์œผ๋กœ ๋กœ์ง ๋‚ด์— ์กด์žฌํ•˜๋Š” ์กฐ๊ฑด๋ฌธ, ๋ฐ˜๋ณต๋ฌธ์„ ์ œ๊ฑฐํ•˜์—ฌ ๋ณต์žก์„ฑ์„ ํ•ด๊ฒฐํ•˜๊ณ , ๋ณ€์ˆ˜์˜ ์‚ฌ์šฉ์„ ์–ต์ œํ•˜์—ฌ ์ƒํƒœ ๋ณ€๊ฒฝ์„ ํ”ผํ•˜๋ ค๋Š” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํŒจ๋Ÿฌ๋‹ค์ž„์„ ๋งํ•œ๋‹ค. ์ฆ‰, ์ˆœ์ˆ˜ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ๋ถ€์ˆ˜ ํšจ๊ณผ๋ฅผ ์ตœ๋Œ€ํ•œ ์–ต์ œํ•˜์—ฌ ์˜ค๋ฅ˜๋ฅผ ํ”ผํ•˜๊ณ  ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ์•ˆ์ •์„ฑ์„ ๋†’์ด๋ ค๋Š” ๊ฒƒ์ด๋‹ค.

 

ํผ์ŠคํŠธ ํด๋ž˜์Šค(First-Class) ํ•จ์ˆ˜

๊ณ ์ฐจ ํ•จ์ˆ˜๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ํ•จ์ˆ˜๋ฅผ ๋ฐ›์•„์˜จ๋‹ค. ์•„๋ž˜ ์˜ˆ์‹œ๋Š” ๋ณ€์ˆ˜ func์— true๋ฅผ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ํ• ๋‹นํ•œ๋‹ค.

const func = function () {
    return true;
};

console.log(func);
  • ํ”ํžˆ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ๋Š” ํ•จ์ˆ˜๋ฅผ ํผ์ŠคํŠธ ํด๋ž˜์Šค ์‹œํ‹ฐ์ฆŒ(First Class Citizen)์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. ์‰ฝ๊ฒŒ ๋งํ•˜๋ฉด ๋ชจ๋“  ๊ถŒ๋ฆฌ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.
  • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ object, string, number์™€ ๊ฐ™์€ ํƒ€์ž…์œผ๋กœ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์€ ํ•จ์ˆ˜๋กœ๋„ ํ•  ์ˆ˜ ์žˆ๋‹ค. ํ•จ์ˆ˜๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋‹ค๋ฅธ ํ•จ์ˆ˜์— ๋„˜๊ธธ ์ˆ˜๋„ ์žˆ๊ณ , ํ•จ์ˆ˜๋ฅผ ๋‹ค๋ฅธ ๋ณ€์ˆ˜์— ํ• ๋‹นํ•˜๊ฑฐ๋‚˜ ๋‹ค๋ฅธ ๊ณณ์œผ๋กœ ๋„˜๊ธธ ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ํŠน์„ฑ ๋•Œ๋ฌธ์— ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์— ์กด์žฌํ•˜๋Š” ํ•จ์ˆ˜๋“ค์ด ํผ์ŠคํŠธ ํด๋ž˜์Šค ํ•จ์ˆ˜๋ผ ๋ถˆ๋ฆฌ๋Š” ๊ฒƒ์ด๋‹ค.

 

๐Ÿ” ๊ณ ์ฐจ ํ•จ์ˆ˜์˜ ์ข…๋ฅ˜


Array.prototype.forEach()

  • for๋ฌธ์„ ๋Œ€์ฒดํ•˜๋Š” ๊ณ ์ฐจํ•จ์ˆ˜๋กœ, ์ฃผ์–ด์ง„ ํ•จ์ˆ˜๋ฅผ ๋ฐฐ์—ด ์š”์†Œ ๊ฐ๊ฐ์— ๋Œ€ํ•ด ์‹คํ–‰ํ•œ๋‹ค.
arr.forEach(callback(currentvalue[, index[, array]])[, thisArg])

  • callback: ๊ฐ ์š”์†Œ์— ๋Œ€ํ•ด ์‹คํ–‰ํ•  ํ•จ์ˆ˜
    • currentValue: ์ฒ˜๋ฆฌํ•  ํ˜„์žฌ ์š”์†Œ
    • index: ์ฒ˜๋ฆฌํ•  ํ˜„์žฌ ์š”์†Œ์˜ ์ธ๋ฑ์Šค
    • array: forEach()๋ฅผ ํ˜ธ์ถœํ•œ ๋ฐฐ์—ด
  • thisArg: callback์„ ์‹คํ–‰ํ•  ๋•Œ this๋กœ ์‚ฌ์šฉํ•  ๊ฐ’, ์ „๋‹ฌํ•˜์ง€ ์•Š์œผ๋ฉด undefined๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
  • ์•„๋ž˜ ์˜ˆ์‹œ๋Š” forEach()๋ฅผ ์‚ฌ์šฉํ•ด items ๋ฐฐ์—ด์˜ ๊ฐ’๋“ค์„ ๋ฏธ๋ฆฌ ์„ ์–ธํ•œ copy์— pushํ•œ๋‹ค.
const items = ["item1", "item2", "item3"];
const copy = [];

items.forEach(function (item) {
    copy.push(item);
});

console.log(copy); // [ 'item1', 'item2', 'item3' ]
const items = ["item1", "item2", "item3"];
const copy = [];

items.forEach((item) => {
    copy.push(item);
});

console.log(copy); // [ 'item1', 'item2', 'item3' ]

 

  • forEach()๋กœ ์ฒ˜๋ฆฌํ•  ์š”์†Œ์˜ ๋ฒ”์œ„๋Š” ์ตœ์ดˆ callback ํ˜ธ์ถœ ์ „์— ์„ค์ •ํ•œ๋‹ค. forEach() ํ˜ธ์ถœ์„ ์‹œ์ž‘ํ•œ ๋’ค ๋ฐฐ์—ด์— ์ถ”๊ฐ€ํ•œ ์š”์†Œ๋Š” callback์ด ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • ๋ฐฐ์—ด์˜ ๊ธฐ์กด ์š”์†Œ๊ฐ’์ด ๋ฐ”๋€ ๊ฒฝ์šฐ, callback์— ์ „๋‹ฌํ•˜๋Š” ๊ฐ’์€ forEach()๊ฐ€ ์š”์†Œ๋ฅผ ๋ฐฉ๋ฌธํ•œ ์‹œ์ ์˜ ๊ฐ’์„ ์‚ฌ์šฉํ•œ๋‹ค. ๋ฐฉ๋ฌธํ•˜๊ธฐ ์ „์— ์‚ญ์ œํ•œ ์š”์†Œ๋Š” ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š๋Š”๋‹ค.
const items = ["item1", "item2", "item3"];
const copy = [];
items.shift();

items.forEach(function (item) {
    copy.push(item);
});

console.log(copy); // [ 'item2', 'item3' ]

 

Array.prototype.map()

  • https://trustmitt.tistory.com/4
  • forEach()์ฒ˜๋Ÿผ ์ˆœํšŒํ•˜๋ฉด์„œ ์ฝœ๋ฐฑ ํ•จ์ˆ˜์—์„œ์˜ ์‹คํ–‰๊ฒฐ๊ณผ๋ฅผ ๋ฆฌํ„ดํ•œ ๊ฐ’์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด ๋ฐ˜ํ™˜ํ•œ๋‹ค.
arr.map(callback(currentValue[, index[, array]])[, thisArg])

  • callback: ์ƒˆ๋กœ์šด ๋ฐฐ์—ด ์š”์†Œ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜
    • currentValue: ์ฒ˜๋ฆฌํ•  ํ˜„์žฌ ์š”์†Œ
    • index(Optional): ์ฒ˜๋ฆฌํ•  ํ˜„์žฌ ์š”์†Œ์˜ ์ธ๋ฑ์Šค
    • array(Optional): map()์„ ํ˜ธ์ถœํ•œ ๋ฐฐ์—ด
  • thisArg(Optional): callback์„ ์‹คํ–‰ํ•  ๋•Œ this๋กœ ์‚ฌ์šฉ๋˜๋Š” ๊ฐ’
  • ์•„๋ž˜ ์˜ˆ์‹œ๋Š” map()์„ ์‚ฌ์šฉํ•ด ์—ฐ์‚ฐํ•œ ๊ฒฐ๊ณผ๊ฐ’์„ ๋„ฃ์–ด ๋ฐฐ์—ด arr์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
const items = [1, 2, 3, 4];
const arr = items.map((item) => {
    return item % 2 == 0 ? "even" : "odd";
});

console.log(arr); // [ 'odd', 'even', 'odd', 'even' ]

 

forEach()์™€ map()

๋‘ ๋ฉ”์„œ๋“œ ๋ชจ๋‘ ๋ฐฐ์—ด์„ ์ˆœํšŒํ•˜๋Š” ๊ฒƒ์€ ๋™์ผํ•˜์ง€๋งŒ, forEach()์˜ ๊ฒฝ์šฐ ๊ฐ ์š”์†Œ๋ฅผ ์ฐธ์กฐํ•œ ์—ฐ์‚ฐ์ด ์ด๋ฃจ์–ด์ง€๊ณ , map()์˜ ๊ฒฝ์šฐ ๊ฐ ์š”์†Œ๋ฅผ ๋‹ค๋ฅธ ๊ฐ’์œผ๋กœ ๋งคํ•‘ํ•œ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์ด ๋ฐ˜ํ™˜๋˜๋Š” ์ ์— ์ฐจ์ด๊ฐ€ ์žˆ๋‹ค.

๊ฒฐ๋ก ์ ์œผ๋กœ, forEach()๋Š” for๋ฌธ์„ ๋Œ€์ฒดํ•˜์—ฌ ์‚ฌ์šฉํ•˜๊ณ , map()์€ ์—ฐ์‚ฐ์˜ ๊ฒฐ๊ณผ๋กœ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉ๋œ๋‹ค.

 

Array.prototype.find()

  • find() ๋ฉ”์„œ๋“œ๋Š” ์ฃผ์–ด์ง„ ํŒ๋ณ„ ํ•จ์ˆ˜๋ฅผ ๋งŒ์กฑํ•˜๋Š” ์ฒซ ๋ฒˆ์งธ ์š”์†Œ์˜ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
  • ๋งŒ์กฑํ•˜๋Š” ๊ฐ’์ด ์—†๋‹ค๋ฉด undefined๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
arr.find(callback[, thisArg])

  • callback: ๋ฐฐ์—ด์˜ ๊ฐ ๊ฐ’์— ๋Œ€ํ•ด ์‹คํ–‰ํ•  ํ•จ์ˆ˜
    • element(Optional): ์ฝœ๋ฐฑ ํ•จ์ˆ˜์—์„œ ์ฒ˜๋ฆฌํ•  ํ˜„์žฌ ์š”์†Œ
    • index(Optional): ์ฝœ๋ฐฑ ํ•จ์ˆ˜์—์„œ ์ฒ˜๋ฆฌํ•  ํ˜„์žฌ ์š”์†Œ์˜ ์ธ๋ฑ์Šค
    • array(Optional): find ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•œ ๋ฐฐ์—ด
  • thisArg: ์ฝœ๋ฐฑ์ด ํ˜ธ์ถœ๋  ๋•Œ this๋กœ ์‚ฌ์šฉํ•  ๊ฐ์ฒด
  • ์•„๋ž˜ ์˜ˆ์‹œ๋Š” find()๋ฅผ ์‚ฌ์šฉํ•ด name์ด ‘mitt’์ธ ๊ฐ์ฒด๋ฅผ ์ฐพ๋Š”๋‹ค.
const arr = [
    { name: "mitt", age: 28 },
    { name: "sophie", age: 26 },
    { name: "tommy", age: 23 },
];

const result = arr.find((person) => person.name == "mitt");

console.log(result); // { name: 'mitt', age: 28 }
  • callback์€ 0๋ถ€ํ„ฐ length-1๊นŒ์ง€ ๋ฐฐ์—ด์˜ ๋ชจ๋“  ์ธ๋ฑ์Šค์— ๋Œ€ํ•ด ํ˜ธ์ถœ๋˜๋ฉฐ, ๊ฐ’์ด ์ง€์ •๋˜์ง€ ์•Š์€ ์š”์†Œ๋„ ํฌํ•จํ•œ๋‹ค.
  • thisArg ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์ฃผ์–ด์ง„ ๊ฒฝ์šฐ์—๋Š” thisArg๊ฐ€ callback ์•ˆ์—์„œ this๋กœ ์‚ฌ์šฉ๋˜๊ณ , ๊ทธ๋ ‡์ง€ ์•Š์€ ๊ฒฝ์šฐ undefined๊ฐ€ this๋กœ ์‚ฌ์šฉ๋œ๋‹ค.
  • find()๋Š” ํ˜ธ์ถœ์˜ ๋Œ€์ƒ์ด ๋œ ๋ฐฐ์—ด์„ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • find()๊ฐ€ ์ฒ˜๋ฆฌํ•  ๋ฐฐ์—ด ์š”์†Œ์˜ ๋ฒ”์œ„๋Š” ์ฒซ callback์ด ํ˜ธ์ถœ๋˜๊ธฐ ์ „์— ๊ฒฐ์ •๋œ๋‹ค. find() ๋ฉ”์„œ๋“œ๊ฐ€ ์‹คํ–‰๋œ ์ดํ›„์— ๋ฐฐ์—ด์— ์ถ”๊ฐ€๋œ ์š”์†Œ๋“ค์— ๋Œ€ํ•ด์„œ๋Š” callback์ด ํ˜ธ์ถœ๋˜์ง€ ์•Š๋Š”๋‹ค.

 

Array.prototype.findIndex()

  • findIndex() ๋ฉ”์„œ๋“œ๋Š” ์ฃผ์–ด์ง„ ํŒ๋ณ„ ํ•จ์ˆ˜๋ฅผ ๋งŒ์กฑํ•˜๋Š” ๋ฐฐ์—ด์˜ ์ฒซ ๋ฒˆ์งธ ์š”์†Œ์— ๋Œ€ํ•œ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
  • ์•ž์„œ ๊ธฐ์žฌํ•œ find()๋กœ ๋ฐ˜ํ™˜๋˜๋Š” ๊ฐ’์˜ ์ธ๋ฑ์Šค ๋ฒˆํ˜ธ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.
  • ๋ฐฐ์—ด ๋ฉ”์„œ๋“œ indexOf()์˜ ์ฝœ๋ฐฑ ํ•จ์ˆ˜ ๋ฒ„์ „์ด๋‹ค.
  • ๋งŒ์กฑํ•˜๋Š” ์š”์†Œ๊ฐ€ ์—†์œผ๋ฉด -1์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
arr.findIndex(callback(element[, index[, array]])[, thisArg])

  • callback: ๋ฐฐ์—ด์˜ ๊ฐ ๊ฐ’์— ๋Œ€ํ•ด ์‹คํ–‰ํ•  ํ•จ์ˆ˜
    • element: ๋ฐฐ์—ด์—์„œ ์ฒ˜๋ฆฌ ์ค‘์ธ ํ˜„์žฌ ์š”์†Œ
    • index: element์˜ ์ธ๋ฑ์Šค
    • array: findIndex ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋œ ๋ฐฐ์—ด
    • thisArg: ์ฝœ๋ฐฑ์„ ์‹คํ–‰ํ•  ๋•Œ this๋กœ ์‚ฌ์šฉ๋  ๊ฐ์ฒด
  • ์•„๋ž˜ ์˜ˆ์‹œ๋Š” find()์˜ ์˜ˆ์‹œ์™€ ๋™์ผํ•˜๋ฉฐ, index ⇒ findIndex()๋กœ ๊ต์ฒดํ•œ ๊ฒƒ์ด๋‹ค.
const arr = [
    { name: "mitt", age: 28 },
    { name: "sophie", age: 26 },
    { name: "tommy", age: 23 },
];

const result = arr.findIndex((person) => person.name == "mitt");

console.log(result); // 0

 

Array.prototype.filter()

  • filter() ๋ฉ”์„œ๋“œ๋Š” ์ฃผ์–ด์ง„ ํ•จ์ˆ˜์˜ ํ…Œ์ŠคํŠธ๋ฅผ ํ†ต๊ณผํ•˜๋Š” ๋ชจ๋“  ์š”์†Œ๋ฅผ ๋ชจ์•„ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
  • find()์˜ ๊ฐ’์„ ์ฐพ์•„ map()์œผ๋กœ ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•˜๋Š” ๊ฑธ ํ•œ ๋ฒˆ์— ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.
arr.filter(callback(element[, index[, array]])[, thisArg])

  • callback: ๊ฐ ์š”์†Œ๋ฅผ ์‹œํ—˜ํ•  ํ•จ์ˆ˜, true๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด ์š”์†Œ๋ฅผ ์œ ์ง€ํ•˜๊ณ , false๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉฐ ๋ฒ„๋ฆฐ๋‹ค.
    • element: ์ฒ˜๋ฆฌํ•  ํ˜„์žฌ ์š”์†Œ
    • index: ํ˜„์žฌ ์š”์†Œ์˜ ์ธ๋ฑ์Šค
    • array: filter๋ฅผ ํ˜ธ์ถœํ•œ ๋ฐฐ์—ด
  • thisArg: callback์„ ์‹คํ–‰ํ•  ๋•Œ this๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ’
  • ์•„๋ž˜ ์˜ˆ์‹œ๋Š” filter()๋ฅผ ์‚ฌ์šฉํ•ด ์ด๋ฆ„์— ‘m’ ๋ฌธ์ž์—ด์ด ํฌํ•จ๋œ ๊ฐ’๋“ค๋กœ๋งŒ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋งŒ๋“  ๊ฒƒ์ด๋‹ค.
const arr = ["mitt", "sophie", "tommy", "jerry"];
const filterArr = arr.filter((name) => {
    return name.includes("m");
});

console.log(filterArr); // [ 'mitt', 'tommy' ]

 

Array.prototype.reduce()

  • reduce() ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด์˜ ๊ฐ ์š”์†Œ์— ๋Œ€ํ•ด ๋ฆฌ๋“€์„œ ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ํ•˜๋‚˜์˜ ๊ฒฐ๊ณผ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
  • ๋ฆฌ๋“€์„œ(reducer) ํ•จ์ˆ˜
    • ๋ˆ„์‚ฐ๊ธฐ(acc)
    • ํ˜„์žฌ ๊ฐ’(cur)
    • ํ˜„์žฌ ์ธ๋ฑ์Šค(idx)
    • ์›๋ณธ ๋ฐฐ์—ด(src)
  • ๋ฆฌ๋“€์„œ ํ•จ์ˆ˜์˜ ๋ฐ˜ํ™˜ ๊ฐ’์€ ๋ˆ„์‚ฐ๊ธฐ์— ํ• ๋‹น๋˜๊ณ , ๋ˆ„์‚ฐ๊ธฐ๋Š” ์ˆœํšŒ ์ค‘ ์œ ์ง€๋˜๋ฏ€๋กœ ๊ฒฐ๊ตญ ์ตœ์ข… ๊ฒฐ๊ณผ๋Š” ํ•˜๋‚˜์˜ ๊ฐ’์ด ๋œ๋‹ค. ์ฒซ ๋ฒˆ์งธ cur๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ ์ˆœํšŒํ•˜๋ฉฐ acc += cur๋ฅผ ์‹คํ–‰
  • forEach, map, filter ๊ธฐ๋Šฅ์„ ๋ชจ๋‘ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์–ด ๊ณ ์ฐจํ•จ์ˆ˜์˜ ๋ถ€๋ชจ๋ผ๊ณ  ๋ถˆ๋ฆฐ๋‹ค.
arr.reduce(callback[, initialValue])

  • callback: ๋ฐฐ์—ด์˜ ๊ฐ ์š”์†Œ์— ๋Œ€ํ•ด ์‹คํ–‰ํ•  ํ•จ์ˆ˜
    • accumulator: ๋ˆ„์‚ฐ๊ธฐ๋Š” ์ฝœ๋ฐฑ์˜ ๋ฐ˜ํ™˜๊ฐ’์„ ๋ˆ„์ ํ•œ๋‹ค. ์ฝœ๋ฐฑ์˜ ์ด์ „ ๋ฐ˜ํ™˜๊ฐ’ ๋˜๋Š” ์ฝœ๋ฐฑ์˜ ์ฒซ ๋ฒˆ์งธ ํ˜ธ์ถœ์ด๋ฉด์„œ initialValue๋ฅผ ์ œ๊ณตํ•œ ๊ฒฝ์šฐ์—๋Š” initialValue์˜ ๊ฐ’์ด๋‹ค.
    • currentValue: ์ฒ˜๋ฆฌํ•  ํ˜„์žฌ ์š”์†Œ
    • currentIndex: ์ฒ˜๋ฆฌํ•  ํ˜„์žฌ ์š”์†Œ์˜ ์ธ๋ฑ์Šค, initialValue๋ฅผ ์ œ๊ณตํ•œ ๊ฒฝ์šฐ 0, ์•„๋‹ˆ๋ฉด 1๋ถ€ํ„ฐ ์‹œ์ž‘
    • array: reduce๋ฅผ ํ˜ธ์ถœํ•œ ๋ฐฐ์—ด
  • initialValue: callback์˜ ์ตœ์ดˆ ํ˜ธ์ถœ์—์„œ ์ฒซ ๋ฒˆ์งธ ์ธ์ˆ˜์— ์ œ๊ณตํ•˜๋Š” ๊ฐ’, ์ดˆ๊ธฐ ๊ฐ’์„ ์ œ๊ณตํ•˜์ง€ ์•Š์œผ๋ฉด ๋ฐฐ์—ด์˜ ์ฒซ ๋ฒˆ์งธ ์š”์†Œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ๋นˆ ๋ฐฐ์—ด์—์„œ ์ดˆ๊ธฐ๊ฐ’ ์—†์ด reduce()๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
  • ๋ฐฐ์—ด์ด ๋น„์–ด ์žˆ๋Š”๋ฐ initialValue๋„ ์ œ๊ณตํ•˜์ง€ ์•Š์œผ๋ฉด TypeError๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค. ๋ฐฐ์—ด์˜ ์š”์†Œ๊ฐ€ ํ•˜๋‚˜ ๋ฟ์ด๋ฉด์„œ initialValue๋ฅผ ์ œ๊ณตํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ, ๋˜๋Š” initialValue๋Š” ์ฃผ์–ด์กŒ์œผ๋‚˜ ๋ฐฐ์—ด์ด ๋นˆ ๊ฒฝ์šฐ์—” ๊ทธ ๋‹จ๋… ๊ฐ’์„ callback ํ˜ธ์ถœ ์—†์ด ๋ฐ˜ํ™˜ํ•œ๋‹ค.
  • ์•„๋ž˜ ์˜ˆ์‹œ๋Š” reduce()๋ฅผ ์‚ฌ์šฉํ•ด ๋ฐฐ์—ด์˜ ๋ชจ๋“  ๊ฐ’์˜ ํ•ฉ์„ ๊ตฌํ•œ ๊ฒƒ์ด๋‹ค.
const total = [1, 2, 3, 4].reduce((acc, cur) => acc + cur, 0);
console.log(total); // 10

 

reduce() ํ˜ธ์ถœ ์‹œ initialValue ๊ฐ’์ด ์—†๋Š” ๊ฒฝ์šฐ
- acc: ๋ฐฐ์—ด์˜ ์ฒซ ๋ฒˆ์งธ ๊ฐ’
- cur: ๋ฐฐ์—ด์˜ ๋‘ ๋ฒˆ์งธ ๊ฐ’

reduce() ํ˜ธ์ถœ ์‹œ initialValue ๊ฐ’์ด ์žˆ๋Š” ๊ฒฝ์šฐ
- acc: initialValue๊ฐ€ ์ง€์ •ํ•œ ๊ฐ’
- cur: ๋ฐฐ์—ด์˜ ์ฒซ ๋ฒˆ์งธ ๊ฐ’

 

Array.prototype.sort()

  • sort() ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด์˜ ์š”์†Œ๋ฅผ ์ ์ ˆํ•œ ์œ„์น˜์— ์ •๋ ฌํ•œ ํ›„ ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. ๊ธฐ๋ณธ ์ •๋ ฌ ์ˆœ์„œ๋Š” ๋ฌธ์ž์—ด์˜ ์œ ๋‹ˆ์ฝ”๋“œ ์ฝ”๋“œ ํฌ์ธํŠธ๋ฅผ ๋”ฐ๋ฅธ๋‹ค.
  • ๋ฐฐ์—ด ๋ณต์‚ฌ๋ณธ์ด ๋งŒ๋“ค์–ด์ง€๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ ์› ๋ฐฐ์—ด์ด ์ •๋ ฌ๋œ๋‹ค.
  • ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ๋ฐฐ์—ด์˜ ์›์†Œ๋“ค์„ ์–ด๋Š ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ• ์ง€ ์ง€์ •ํ•ด์•ผ ํ•œ๋‹ค.
arr.sort([compareFunction])

  • compareFunction: ์ •๋ ฌ ์ˆœ์„œ๋ฅผ ์ •์˜ํ•˜๋Š” ํ•จ์ˆ˜, ์ƒ๋žตํ•˜๋ฉด ๋ฐฐ์—ด์€ ๊ฐ ์š”์†Œ์˜ ๋ฌธ์ž์—ด ๋ณ€ํ™˜์— ๋”ฐ๋ผ ๊ฐ ๋ฌธ์ž์˜ ์œ ๋‹ˆ์ฝ”๋“œ ํฌ์ธํŠธ ๊ฐ’์— ๋”ฐ๋ผ ์ •๋ ฌ๋œ๋‹ค.
  • ์•„๋ž˜ ์˜ˆ์‹œ๋Š” ๋ฐฐ์—ด์„ ABC ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ ๊ฒƒ์ด๋‹ค.
let arr = ["mitt", "sophie", "bolt", "woodie"];
arr.sort();

console.log(arr); // [ 'bolt', 'mitt', 'sophie', 'woodie' ]

 

  • ์ˆซ์ž๋ฅผ ์ •๋ ฌํ•˜๋Š” ๊ฒฝ์šฐ์—๋„ ๋ฌธ์ž์™€ ๊ฐ™์ด ์ •๋ ฌ๋˜๋ฏ€๋กœ ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋ฅผ ๋„ฃ์–ด ์กฐ์ž‘์ด ํ•„์š”ํ•˜๋‹ค.
let arr = [7, 1, 24, 9, 12, 32];
arr.sort();
console.log(arr); // [ 1, 12, 24, 32, 7, 9 ]

arr.sort(function (a, b) {
    return a - b;
});

console.log(arr); // [ 1, 7, 9, 12, 24, 32 ] :: ์˜ค๋ฆ„์ฐจ์ˆœ

arr.sort(function (a, b) {
    return b - a;
});

console.log(arr); // [ 32, 24, 12, 9, 7, 1 ] :: ๋‚ด๋ฆผ์ฐจ์ˆœ

 

  • ๊ฐ์ฒด์˜ ์†์„ฑ ๊ฐ’์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ
let arr = [
    { name: "mitt", age: 28 },
    { name: "tommy", age: 23 },
    { name: "sophie", age: 26 },
    { name: "jerry", age: 25 },
];

arr.sort(function (a, b) {
    return a.age - b.age; // age๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ
});

console.log(arr);
/* [
  { name: 'tommy', age: 23 },
  { name: 'jerry', age: 25 },
  { name: 'sophie', age: 26 },
  { name: 'mitt', age: 28 }
] */

 

Array.prototype.some()

  • some() ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด ์•ˆ์˜ ์–ด๋–ค ์š”์†Œ๋ผ๋„ ์ฃผ์–ด์ง„ ํŒ๋ณ„ ํ•จ์ˆ˜๋ฅผ ํ†ต๊ณผํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธํ•œ๋‹ค.
  • ํ•œ ๊ฐœ๋ผ๋„ ํ†ต๊ณผ๋˜๋ฉด true, ์•„๋‹ ๋•Œ์—๋Š” false๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ณ , ๋นˆ ๋ฐฐ์—ด์—์„œ ํ˜ธ์ถœํ•˜๋ฉด ๋ฌด์กฐ๊ฑด false๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
arr.some(callback[, thisArg])

  • callback: ๊ฐ ์š”์†Œ๋ฅผ ์‹œํ—˜ํ•  ํ•จ์ˆ˜
    • currentValue: ์ฒ˜๋ฆฌํ•  ํ˜„์žฌ ์š”์†Œ
    • index: ์ฒ˜๋ฆฌํ•  ํ˜„์žฌ ์š”์†Œ์˜ ์ธ๋ฑ์Šค
    • array: some์„ ํ˜ธ์ถœํ•œ ๋ฐฐ์—ด
  • thisArg: callback์„ ์‹คํ–‰ํ•  ๋•Œ this๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ’
  • ์•„๋ž˜ ์˜ˆ์‹œ๋Š” ๋ฐฐ์—ด์˜ ์š”์†Œ๋ฅผ 2๋กœ ๋‚˜๋ˆ„์—ˆ์„ ๋•Œ ๋‚˜๋จธ์ง€๊ฐ€ 0์ธ ๊ฐ’์ด ์žˆ๋Š”์ง€ some() ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ์ฒดํฌํ•˜์˜€๋‹ค. ๋ฐฐ์—ด์˜ ๋ชจ๋“  ์š”์†Œ๊ฐ€ ์กฐ๊ฑด์— ๋ถ€ํ•ฉํ•˜์ง€ ์•Š์•„ false๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
let arr = [1, 3, 5, 7];
let result = arr.some((cur) => {
    return cur % 2 == 0;
});

console.log(result); // false

 

  • ํ•˜๋‚˜๋ผ๋„ ์กฐ๊ฑด์— ๋ถ€ํ•ฉํ•˜๋ฉด true๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
let arr = [1, 3, 5, 6];
let result = arr.some((cur) => {
    return cur % 2 == 0;
});

console.log(result); // true

 

Array.prototype.every()

  • every() ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด ์•ˆ์˜ ๋ชจ๋“  ์š”์†Œ๊ฐ€ ์ฃผ์–ด์ง„ ํŒ๋ณ„ ํ•จ์ˆ˜๋ฅผ ํ†ต๊ณผํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธํ•œ๋‹ค.
  • some()์˜ ๋ฐ˜๋Œ€ ๋ฒ„์ „, ๋ฐฐ์—ด ์•ˆ์˜ ๋ชจ๋“  ์š”์†Œ๊ฐ€ ์ฃผ์–ด์ง„ ์กฐ๊ฑด์„ ๋ชจ๋‘ ํ†ต๊ณผํ•˜๋ฉด true, ํ•œ ์š”์†Œ๋ผ๋„ ํ†ต๊ณผํ•˜์ง€ ๋ชปํ•˜๋ฉด false๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
  • ๋นˆ ๋ฐฐ์—ด์„ ํ•จ์ˆ˜์— ์ ์šฉํ•˜๋ฉด ๋ฌด์กฐ๊ฑด true๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
arr.every(callbackFn(index[, array]])[, thisArg])

  • callbackFn: ๊ฐ ์š”์†Œ๋ฅผ ์‹œํ—˜ํ•  ํ•จ์ˆ˜
    • index: ์ฒ˜๋ฆฌํ•  ํ˜„์žฌ ์š”์†Œ์˜ ์ธ๋ฑ์Šค
    • array: every๋ฅผ ํ˜ธ์ถœํ•œ ๋ฐฐ์—ด
  • thisArg: callbackFn์„ ์‹คํ–‰ํ•  ๋•Œ this๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ’
  • ์•„๋ž˜ ์˜ˆ์‹œ๋Š” ๋ฐฐ์—ด์˜ ์š”์†Œ๋ฅผ 2๋กœ ๋‚˜๋ˆ„์—ˆ์„ ๋•Œ ๋‚˜๋จธ์ง€๊ฐ€ 1์ธ์ง€ every() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•ด ํŒ๋ณ„ํ•œ ๊ฒƒ์ด๋‹ค. ๋ชจ๋“  ๊ฐ’์ด ์กฐ๊ฑด์— ๋งŒ์กฑํ•˜๋ฏ€๋กœ true๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
let arr = [1, 3, 5, 7];
let result = arr.every((cur) => {
    return cur % 2 == 1;
});

console.log(result); // true

 

  • ํ•˜๋‚˜๋ผ๋„ ์กฐ๊ฑด์— ๋ถ€ํ•ฉํ•˜์ง€ ์•Š์œผ๋ฉด false๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
let arr = [1, 3, 5, 6];
let result = arr.every((cur) => {
    return cur % 2 == 1;
});

console.log(result); // false

 

๐Ÿ” ๊ณ ์ฐจ ํ•จ์ˆ˜์˜ ์‹œ๊ฐํ™” ๋น„๊ต


  • Array.prototype.copyWithin()
    • ๋ฐฐ์—ด ์ผ๋ถ€๋ฅผ ๋ณต์‚ฌํ•ด ์ง€์ •๋œ ์œ„์น˜์— ๋ฎ์–ด์“ฐ๊ณ  ํ•ด๋‹น ๋ฐฐ์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
    • arr.copyWithin(target, start, end);

 

๐Ÿ” ๊ณ ์ฐจ ํ•จ์ˆ˜์˜ ๋™์ž‘ ์˜ˆ์ œ


  • ์˜ˆ์ œ 1
    • ํƒœ์–ด๋‚œ ํ•ด๊ฐ€ ๋“ค์–ด ์žˆ๋Š” ๋ฐฐ์—ด๋กœ ์‚ฌ๋žŒ๋“ค์˜ ๋‚˜์ด๋ฅผ ๊ณ„์‚ฐํ•ด์„œ ๋ฐ˜ํ™˜ํ•˜๊ณ ์ž ํ•œ๋‹ค.
const birthYear = [1995, 1997, 1994, 2000];

// ๊ณ ์ฐจ ํ•จ์ˆ˜๊ฐ€ ์•„๋‹Œ ํ•จ์ˆ˜
const ages1 = [];

for (let i = 0; i < birthYear.length; i++) {
    let age1 = 2022 - birthYear[i];
    ages1.push(age1);
}

// ๊ณ ์ฐจ ํ•จ์ˆ˜๋กœ ์ž‘์„ฑ -- map() ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ
const ages2 = birthYear.map((year) => 2022 - year);

console.log(ages1); // [ 27, 25, 28, 22 ]
console.log(ages2); // [ 27, 25, 28, 22 ]

 

  • ์˜ˆ์ œ 2
    • ์‚ฌ๋žŒ๋“ค์˜ ์ด๋ฆ„๊ณผ ๋‚˜์ด๋กœ ๊ตฌ์„ฑ๋œ ๊ฐ์ฒด ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ–ˆ์„ ๋•Œ, 25์‚ด ์ด์ƒ์˜ ์‚ฌ๋žŒ๋“ค๋งŒ ํ•„ํ„ฐ๋ง๋œ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด์„ ๋งŒ๋“ค๊ณ ์ž ํ•œ๋‹ค.
const arr = [
    { name: "mitt", age: 28 },
    { name: "sophie", age: 26 },
    { name: "tommy", age: 23 },
    { name: "jerry", age: 25 },
    { name: "mayson", age: 19 },
];

// ๊ณ ์ฐจ ํ•จ์ˆ˜๊ฐ€ ์•„๋‹Œ ํ•จ์ˆ˜
const newArr1 = [];

for (let i = 0; i < arr.length; i++) {
    if (arr[i].age >= 25) {
        newArr1.push(arr[i]);
    }
}

// ๊ณ ์ฐจ ํ•จ์ˆ˜ --  filter() ๋ฉ”์„œ๋“œ ์‚ฌ์šฉ
const newArr2 = arr.filter((person) => person.age >= 25);

console.log(newArr1);
/* [
  { name: 'mitt', age: 28 },
  { name: 'sophie', age: 26 },
  { name: 'jerry', age: 25 }
] */

console.log(newArr2);
/* [
  { name: 'mitt', age: 28 },
  { name: 'sophie', age: 26 },
  { name: 'jerry', age: 25 }
] */

 

๐Ÿ” ๊ณ ์ฐจ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ 


์ถ”์ƒํ™”๋ž€ ๋ณต์žกํ•œ ์–ด๋–ค ๊ฒƒ์„ ์••์ถ•ํ•ด์„œ ํ•ต์‹ฌ๋งŒ ์ถ”์ถœํ•œ ์ƒํƒœ๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์„ ๋งํ•˜๋Š”๋ฐ, ์ถ”์ƒํ™”์˜ ๊ด€์ ์—์„œ ๊ณ ์ฐจ ํ•จ์ˆ˜๊ฐ€ ๊ฐ–๋Š” ์ด์ ์ด ์žˆ๋‹ค.

  • ์ถ”์ƒํ™” ⇒ ์ƒ์‚ฐ์„ฑ์˜ ํ–ฅ์ƒ
    • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ฌธ๋ฒ•์„ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋งŒ์œผ๋กœ๋„ ๋‹ค์–‘ํ•œ ํ”„๋กœ๊ทธ๋žจ์„ ๋น„๊ต์  ์‰ฝ๊ฒŒ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด์ฒ˜๋Ÿผ ๋ฌธ์ œ ํ•ด๊ฒฐ์ด ๋” ์‰ฌ์›Œ์ง€๋Š” ๊ฒƒ์ด ์ถ”์ƒํ™”์˜ ์ด์ ์ด๋‹ค.
    • ๋ฐ˜๋ณต๋˜๋Š” ๋กœ์ง์€ ๋ณ„๋„์˜ ํ•จ์ˆ˜๋กœ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด ์ถ”์ƒํ™”์˜ ์ข‹์€ ์‚ฌ๋ก€์ด๋‹ค.
    • ๊ณ ์ฐจ ํ•จ์ˆ˜๋Š” ํ•จ์ˆ˜๋ฅผ ์ „๋‹ฌ ๋ฐ›๊ฑฐ๋‚˜ ๋ฆฌํ„ดํ•˜๊ณ , ํ•จ์ˆ˜์— ๋Œ€ํ•œ ๋กœ์ง์€ ๊ฐ์ถฐ์ ธ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ถ”์ƒํ™”์˜ ์ˆ˜์ค€์ด ๋†’์•„์ง€๋Š” ๋งŒํผ ์ƒ์‚ฐ์„ฑ๋„ ๋†’์•„์ง€๊ฒŒ ๋œ๋‹ค.

 

๐Ÿ” Reference


https://developer.mozilla.org/ko/

https://inpa.tistory.com/entry/JS-๐Ÿ“š-๋ฐฐ์—ด-๊ณ ์ฐจํ•จ์ˆ˜-์ด์ •๋ฆฌ-๐Ÿ’ฏ-mapfilterfindreducesortsomeevery

https://jess2.xyz/JavaScript/higher-order-function/

https://velog.io/@jakeseo_me/์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ-๊ฐœ๋ฐœ์ž๋ผ๋ฉด-์•Œ์•„์•ผ-ํ• -33๊ฐ€์ง€-๊ฐœ๋…-22-์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ-์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ-๊ณ ์ฐจ-ํ•จ์ˆ˜Higher-Order-Function-์ดํ•ดํ•˜๊ธฐ

https://velog.io/@thyoondev/๊ณ ์ฐจ-ํ•จ์ˆ˜higher-order-function์—-๋Œ€ํ•˜์—ฌ