Can someone walk me through it? I don’t understand what parameters are passed and things like that.
<html>
<body>
<script type="text/javascript">
function sortNumber(a, b)
{
return b - a;
}
var n = ["10", "5", "40", "25", "100", "1"];
document.write(n.sort(sortNumber));
</script>
</body>
</html>
sortwill compareatob, and change the array to be in descending order.The
-operator will coerce them toNumber.If you want to see the members being passed as
aandb, output them with something likeconsole.log(if you have a console object).