Home > shorts > Coding reject method with JavaScript

Coding reject method with JavaScript


Coding reject method with JavaScript

Reject method iterates over a given list of element, calls the predicate on each element. It returns the all non-matched cases.

❌ there is no higher-order function in JS ✅ implemented in Underscore.JS, lodash.js, and etc.

function reject(codition, arr) {
    const newArr = []
    for(let i = 0; i < arr.length; i++) {
        !codition(arr[i]) && newArr.push(arr[i])
    }
    return newArr
}

Check the demo here => CodePen

© 2021, Andrew Losseff