I am very new to coding and even new to Javascript. I have done some basic courses, and I myself start to study on my own. I tried to search to answer this question and did not find anything like it. If someone can find this answer, please let me know!
I am trying to write a function that will take a list of numbers (like an array) and sort it from smallest to largest. Since I understand that sort () does not sort numbers correctly, I am trying to write this function based on some search queries that I made.
Here is what I have and honestly, I feel that I am missing a step:
var sort= function(list){
function numberSort (a, b) {
return a - b;
};
numberSort(list);
I get a syntax error. I find it difficult to figure out how to get through an input (list) through an internal function so that sorting can happen.
Can someone explain what is wrong here? I feel that I'm not too sure about the function I found, which helps in sorting numbers.
Thank!
source
share