const partition = (arr, f, a=[], b=[]) => {
    if (arr.length === 0) 
        return [a, b]
    const [x, ...xs] = arr
    return f(x) 
        ? partition(xs, f, [...a, x], [...b])
        : partition(xs, f, [...a], [...b, x])
}

let xs = [1,2,3,4,5]
console.log(partition(xs, x => x % 2));

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: