I want to sort a nested array using splice that looks like this
[ [ 'Ruby', 65 ], [ 'Python', 90 ] , ['Javascript', 10]]
based on the values of the inner arrays in descending order.
expected output:
[[ 'Python', 90 ] , ['Ruby', 65], ['Javascript',10]]
My try:
function ordarray (para){
let results=para
for (let j=0; j<results.length; j++){
if (results[j][1] < results[j+1][1]) {
results.splice(results[j], 0, results[j+1])
}
}
return results
}
When invoked, I get the error message "Cannot read property '1' of undefined"
Thanks for reading!