Skip to content

Instantly share code, notes, and snippets.

@crongro
Last active January 15, 2018 03:43
Show Gist options
  • Save crongro/5a71d5ca4e609acce59d5c15bebb71f8 to your computer and use it in GitHub Desktop.
Save crongro/5a71d5ca4e609acce59d5c15bebb71f8 to your computer and use it in GitHub Desktop.
pari_1207.js
/* 아래처럼 동작가능한 partial 함수를 만들어보세요 */
//add함수는 n개의 인자를 받아서 합을 계산해주는 함수다.
function add() {
let arg = Array.from(arguments);
//reduce는 Array안에 있는 메서드다.
let sum = arg.reduce(function(prev,next) {
return prev+next;
},0);
return sum;
}
//partial 함수는 Function에 추가된 함수라, bind나 call처럼 동작한다.
//partial 함수의 반환값도 함수다.
var addnew = add.partial("미정",3,"미정");
console.log(addnew(1,2)); //6
console.log(addnew(4,5)); //12
//partial은 아래처럼 인자의 순서와 상관 없이 동작해야 한다.
var addnew = add.partial("미정","미정",3);
console.log(addnew(1,2)); //6
console.log(addnew(4,5)); //12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment