• + 2 comments

    I am not sure how to make this 3 lines or less in JS and there is no findZigZagSequence function to debug, but here's my solution (which isn't passing despite the output matching what is expected 🤔) I feel like this is fairly sloppy though.

    function processData(input) {
        const modifiedInput = input.split('\n')
        const middlePosition = Math.floor(modifiedInput[1] / 2)
        const sortedArr = modifiedInput[2].split(' ').sort((a,b) => a-b)
        const middleNumber = sortedArr.pop()
        const resultingArray = []
        for (let a = 0; a < middlePosition; a++) {
            resultingArray.push(sortedArr[a])
        }
        const reversedArray = sortedArr.reverse()
        resultingArray.push(middleNumber)
        for (let a = 0; a < middlePosition; a++) {
            resultingArray.push(reversedArray[a])
        }
        console.log(resultingArray.join(' '))
        return resultingArray.join(' ')
    } 
    `