How to compare 2 powers

1

I need to compare 2 powers that are not formatted ..

Example:
2,2 = 2²
3,3 = 3³

if (2² > 3³)

The numbers arrive in an array, so it comes [2,2,3,3], I need to separate them in pairs and need to turn a power ...

    
asked by anonymous 03.09.2014 / 22:03

1 answer

7

Use Math.pow to calculate the powers, and compare the results. For example:

var entrada = [2,2,3,3];
// confiando que entrada.length >= 4
if(Math.pow(entrada[0], entrada[1]) > Math.pow(entrada[2], entrada[3])) {
   // a primeira dupla é maior
}
    
03.09.2014 / 22:13