flatten two ways

function flatten(source, acc = []) {
    if (source.length === 0) return acc;

    const [head, ...tail] = source;

    return flatten(tail, [...acc, ...(Array.isArray(head) ? flatten(head) : [head])]);
}

console.log(flatten([1,2,[3,4,5,[6,7],8,[9]],10]));
import * as R from 'ramda';

const flatten = R.ifElse(
    R.propSatisfies(R.equals(0), 'length'),
    R.flip(R.identity),
    R.converge((source, acc = []) => flatten(source, acc), [
	    R.tail,
        R.useWith(R.flip(R.concat), [
	        R.pipe(R.head, R.ifElse(Array.isArray, head => flatten(head, []), R.of)),
	        R.identity
        ])
    ])
);

console.log(flatten([1,2,[3,4,5,[6,7],8,[9]],10], []));