I am very new at coding and even newer at Javascript. I've done some basic courses and I'm trying to start learning through challenges on my own. I tried to search to see if this question was answered and didn't find anything similar. If someone can find this answer, please let me know!
I am trying to write a function that will take a list of numbers (as an array) and sort it from least to greatest. Since I understand that sort() doesn't sort numbers correctly, I am trying to write this function based on some googling I did.
Here's what I have and honestly, it feels like I'm missing a step:
var sort= function(list){
function numberSort (a, b) {
return a - b;
};
numberSort(list);
I'm getting a syntax error. I'm having trouble understanding how to pass through the input (list) through the inner function so that the sort can happen.
Could anyone provide further explanation of what's wrong here? I feel like I'm not too solid on the function I found that helps with sorting numbers.
Thanks!
}to the end}bracket. Also, what makes you think thatsort()can't sort numbers?12before3.sort()can take a callback function where you can customize how it sorts.