Wiki Elegant

Function Factory

Create a function that takes a “base number” as an argument. This function should return another function which takes a new argument, and returns the sum of the “base number” and the new argument.

Please check the examples below for a clearer representation of the behavior expected.

Examples

// Calling makePlusFunction(5) returns a new function that takes an input,
// and returns the result when adding 5 to it.

const plusFive = makePlusFunction(5)

plusFive(2) ➞ 7

plusFive(-8) ➞ -3

// Calling makePlusFunction(10) returns a new function that takes an input,
// and returns the result when adding 10 to it.

const plusTen = makePlusFunction(10)

plusTen(0) ➞ 10

plusTen(188) ➞ 198

plusFive(plusTen(0)) ➞ 15
Answer (1)
const makePlusFunction = baseNum => num => baseNum + num;
Answer 2
function makePlusFunction(baseNum) {
return function(x) {
return baseNum + x;
};
}
// Or, more succinctly, with arrow function notation:
// const makePlusFunction = baseNum => x => baseNum + x;
Answer (3)
const makePlusFunction = (base) => (num) => base + num;
Answer (4)
function makePlusFunction(baseNum) {
return function(input){
return baseNum + input;
}
}

Answer (5)
const makePlusFunction = baseNum => x => baseNum + x
Answer (6)
makePlusFunction = (n) => (x) => x+n
Answer(7)
function makePlusFunction(baseNum) {
return function(nb){
return baseNum+nb;
}
}
Answer (8)
function makePlusFunction(baseNum) {
return y => baseNum + y
}
Answer (9)
function makePlusFunction(baseNum) {
return function(a){
return baseNum + a;
}
}
Answer (10)
function makePlusFunction(baseNum) {
return function(newArg){
return baseNum+newArg;
}
}
Answer (11)
function makePlusFunction(baseNum) {
return (x)=>baseNum+x;
}
Answer (12)
function makePlusFunction(baseNum) {
return function (a){
return baseNum + a
}
}
Answer (13)
function makePlusFunction(baseNum) {
return function plusFive(num2)
{
return baseNum+num2;
}
}
Answer(14)
function makePlusFunction(x) {
return function(y){
return x+y
}
}
Answer (15)
function makePlusFunction(baseNum) {
return function(arg){
return baseNum+arg;
};
}
Answer (16)
function makePlusFunction(baseNum, num) {
return (num) => baseNum + num
}
Answer (17)
function makePlusFunction(baseNum) {
return (n) => n + baseNum
}
Answer (18)
function makePlusFunction(baseNum) {
function secondFunction(newArg) {
return newArg + baseNum
}
return secondFunction
}
Answer (19)
function makePlusFunction(baseNum) {
function inner(argument) {
return baseNum + argument;
}
return inner;
}
Answer (20)
function makePlusFunction(baseNum) {
function inner(num){
return baseNum + num
}
return inner
}
Answer (21)
function makePlusFunction(baseNum) {
const newPlusFunction = function(num){
return num+baseNum
}
return newPlusFunction
}
Answer (22)
function makePlusFunction(baseNum) {
return function(anotherNum) {
return baseNum + anotherNum;
}
}
Answer (23)
function makePlusFunction(baseNum) {
return function (newnumber) {
return newnumber+baseNum
}
}
Answer (24)
function makePlusFunction(baseNum) {
return function(num){
return baseNum + num;
}
}
Answer (25)
function makePlusFunction(baseNum) {
return function plusBaseNum(newArg) {
return baseNum + newArg
}
}