Tell us what’s happening:
I’m honestly not sure where to even begin. Can anyone send me website links that could help or in your own words give me a different explanation of what this step is asking? Thanks.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const sortedValues = inputValues.sort((a, b) => {
});
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15
Challenge Information:
Learn Basic Algorithmic Thinking by Building a Number Sorter - Step 44
This one is tricky.
Here is a reference though and see if that helps Array.prototype.sort() - JavaScript | MDN
1 Like
so ive been reading the link you sent me over and im sure this step has to do with the compared function that the mdn page you sent talks about but im not quite sure how to utilize it in code. ive wrote this simple code up that I know im missing something but im not sure how to write the code to have the console sort a before b and vice versa. this is what ive wrote so far.
const sortedValues = inputValues.sort((a, b) => {
if(inputValues < 0) {
return (a, b)
} else {
return (b, a)
}
return sortedValues
});
When you read the step over again or when your read MDN, what do you learn about the callback function? For eg, what parameters does it take and what should it return?
(Ps I edited your post with three backticks above and below the code so it properly formatted for the forum)
1 Like
thanks totally only used one backtick above and below.
1 Like
there I go overthinking things yet again LOL. I got my code to pass by following (a, b) => a - b
which mdn explained to be code that sorts numbers in ascending order. since parameters from the last step were already (a,b) I returned a - b in the callback function and my code passed! I need to remember to simplify things. thanks for your help.
1 Like