The call to n.sort(sortNo) doesn’t specify any parameters for the function sortNo (which defines parameters of a and b). Can anyone explain why?
<script type="text/javascript">
function sortNo(a,b)
{
return a - b;
}
var n = ["10", "5", "40", "25", "100", "1"];
document.write(n.sort(sortNo));
</script>
Is return a - b; the formulae used?
I know that sortNo is provided with two items. Does a numerical operation return the following?
- a negative value, if
ais beforeb - a positive value, if
bis beforea - zero: if
aandbare equal
Both a and b are strings. So a-b makes no sense.
Use