Quicksort 2 - Sorting

  • + 0 comments

    This solution is going crazy for me: I have tried like this

    I have this code:

    function processData(input) {
        //Enter your code here
        //left<p, right>p
        let ar;
        let p = input[0]
        let left = []
        let right = []
    
    
        if (input.length <= 1) return input
        else {
    
            for (let i = 1; i < input.length; i++) {
                if (input[i] > p) {
                    right.push(input[i])
                } else {
                    left.push(input[i])
                }
            }
      
            ar = [...processData(left.slice(0).filter((d) => d < p)), p, ...processData(right.slice(0).filter((d) => d > p))]
            
        }
        console.log(...ar)
    
        return ar
    
    }
    
    
    
    process.stdin.resume();
    process.stdin.setEncoding("ascii");
    _input = "";
    process.stdin.on("data", function (input) {
        _input += input;
    });
    
    
    process.stdin.on("end", function () {
        processData(_input.replace(/\s+$/g, '').split('').map((num) => parseInt(num), 10));
    });
    

    And output is like this:

    2 3
    1 2 3
    1 2 3 5 //How to get rid of this part
    8 9 // and this part
    1 2 3 5 7 8 9
    

    if anybody knows please suggests me!!

    `