DEV Community

Discussion on: Daily Challenge #117 - MinMinMax

Collapse
 
wheatup profile image
Hao

I'm sure there's less time complexity one but this boi will get its job done

const minMinMax = arr => {
    const [min, max] = [...arr].sort().splice(1, arr.length - 3);
    for (let i = min + 1; i < max; i++) {
        if (!arr.includes(i)) {
            return [min, i, max];
        }
    }
    return [min, undefined, max];
}

minMinMax([-1, 4, 5, -23, 24]); // [ -23, -22, 24 ]