Click here to Skip to main content
15,922,325 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
JavaScript
const BigNumber = require('bignumber.js')

const bigSorting = arr => arr.sort( (a, b) => new BigNumber(a).comparedTo(new BigNumber(b)) )



This is code above is online solution of hackerrank bignumber sorting......but here that guy uses compredTo() method which is not present in javascript....but still program run how ?

What I have tried:

JavaScript
function bigSorting(unsorted) {

    
    return unsorted.sort(function(a,b)
    {
        return a -b;
    });

}




This above is my code passes only 7 test cases out of 9....Of big number sorting
Posted
Updated 17-Oct-19 9:16am
Comments
#realJSOP 17-Oct-19 14:54pm    
comparedTo is a function contained in the BigNumber object. You have to look at the source code for that object to find it.

 
Share this answer
 
Comments
Akash Tawade 18-Oct-19 2:27am    
OK..Now I Understood.
comparedTo is a function contained in the BigNumber object. You have to look at the source code for that object to find it.
 
Share this answer
 
Comments
Akash Tawade 17-Oct-19 14:56pm    
@JSOP is BigNumber is special library function for javascript ?
#realJSOP 17-Oct-19 22:02pm    
No, it’s not part of JavaScript that I am aware of.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900