Zig Zag Sequence

  • + 0 comments

    Broken in JS but here is my solution

    function processData(input) {
        const arrStartIndex = input.lastIndexOf('\n');
        const finalArr = input.substring(arrStartIndex + 1).split(' ');
        const sortedArr = finalArr.sort((a, b) => a - b);
        const middleNumber = (sortedArr.length / 2)
        const secondHalf = sortedArr.slice(middleNumber)
        const firstHalf = sortedArr.slice(0, middleNumber)
        const result= [...firstHalf, ...secondHalf.reverse()].join(' ')
        return result;
    }