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 ...
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 ...
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
}