Sorting: Comparator

  • + 0 comments

    JS

    function processData(input) {
        //Enter your code here
    
        const data = input.split('\n');
    
        const arr = []
    
        for (let i = 1; i < data.length; i++) {
            const [name, scores] = data[i].split(' ');
            arr.push([name, scores])
        }
    
    
        const rr = obj.sort((a, b) => {
            if (b[1] !== a[1]) {
                return b[1] - a[1];
            }
            return a[0].localeCompare(b[0]);
        });
    
        const result = rr.map(r => r.join(' ')).join(' \n')
    
        console.log(result);
    
    }