Home > Back-end >  How to send the inner function an array as a parameter?
How to send the inner function an array as a parameter?

Time:12-01

The second function will take the array as a parameter How would you send the inner function as a parameter?

const score = [98, 76, 94, 82, 70, 95, 45, 90]
const determinePass = function (threshold) {
    return function (array) {
        return array.map(function (value) {
            return value > threshold ? "pass" : "fail";
        })
    }
}

kindly assist me if anyone know the solution

CodePudding user response:

this is how you call the return function.

determinePass(threshold)(array);

// for example
// determinePass(50)(score)

const score = [98, 76, 94, 82, 70, 95, 45, 90]
const determinePass = function (threshold) {
    return function (array) {
        return array.map(function (value) {
            return value > threshold ? "pass" : "fail";
        })
    }
}

console.log(determinePass(50)(score));

CodePudding user response:

This returns an array of pass or fail. The parameter is in the determinePass function.

const score = [98, 76, 94, 82, 70, 95, 45, 90]
    
function determinePass(threshold, array){
    return array.map(function (value) {
        return value > threshold ? "pass" : "fail";
    });
}

console.log(determinePass(50, score));

Or

const score = [98, 76, 94, 82, 70, 95, 45, 90]
    
function determinePass(threshold){
    return score.map(function (value) {
        return value > threshold ? "pass" : "fail";
    });
}

console.log(determinePass(50));
  • Related