You are viewing a single comment's thread. Return to all comments →
javascript
function processData(input) { //Enter your code here let arr = input.split("\n").join(" ").split(" "); let n = arr[0]; arr.shift(); let values = []; let names = []; for(let i =0; i < arr.length;i++){ if(i % 2 == 0 || i==0){ names.push(arr[i]); } if(i % 2 == 1){ values.push(parseInt(arr[i])); } } let new_arr = [] let mini_arr = [] for(let j = 0; j < values.length; j++){ mini_arr.push(names[j]); mini_arr.push(values[j]); new_arr.push(mini_arr); mini_arr = []; } values.sort(function(a,b){return a-b}) values.reverse(); new_arr.sort(); new_arr.sort(function(a, b){return b[1]-a[1]}); for(let k = 0; k < new_arr.length; k++){ console.log(new_arr[k][0] + " "+ new_arr[k][1].toString()) } }
Seems like cookies are disabled on this browser, please enable them to open this website
Sorting: Comparator
You are viewing a single comment's thread. Return to all comments →
javascript