Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

in compare method why we taking a and b for sorting in javascript

for compare and sort method:-
  
function compare(a,b) {
    return a - b;
}
------------------

var numbers = [1,5,3.14];
compare(1,5);     // Returns -4, a is less than b
compare(1,3.14);  // Return -2.14, a is less than b
compare(5,3.14);  // returns 1.86, a is greater than b
Comment

PREVIOUS NEXT
Code Example
Javascript :: codemirror get object from textarea 
Javascript :: JavaScript querySelector - By Tag name 
Javascript :: Append to the text in the <p tag 
Javascript :: JavaScript Object Accessors 
Javascript :: node js install aws-sdk 
Javascript :: lodash sum 
Javascript :: live server in javascript 
Javascript :: How to add click event to table row js 
Javascript :: ReactComponent 
Javascript :: axios cors http localhost forbidden 
Javascript :: Iterating set object javascript 
Javascript :: angular material button color 
Javascript :: how to dynamically populate pdf with pdfmake node 
Javascript :: add marker on map geocoder result mapbox 
Javascript :: crypto js 
Javascript :: javascript dom after a element 
Javascript :: how to set onmouseover in javascript 
Javascript :: how to get the current username with wscript 
Javascript :: how to check for null in javascript 
Javascript :: passing json as datasource to jasper report library 
Javascript :: javascript Clone Array Using Spread Operator 
Javascript :: make image onclick in vuejs 
Javascript :: jest always pass async await 
Javascript :: react native radio buttons 
Javascript :: javascript repeat function 
Javascript :: set state 
Javascript :: use excel in js 
Javascript :: jQuery exists function 
Javascript :: click tester 
Javascript :: react map array 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =