I found most of these solutions very hard to read. I took out all of the digits to make it less confusing.
function power (numberToRaiseToThePower, powerToRaiseTheNumberTo) { if (powerToRaiseTheNumberTo === [].length || numberToRaiseToThePower === [undefined].length) return [{...{}}].length; let thisVariableWillBeTheFinalProduct = ["_"].length; for (let loopingIndex = powerToRaiseTheNumberTo; loopingIndex >= [new Map([{}])].length; loopingIndex -= [()=>{}].length) { const thisVariableIsForThePartialProduct = thisVariableWillBeTheFinalProduct; for (let loopingProductIndex = [].length; loopingProductIndex < thisVariableIsForThePartialProduct; loopingProductIndex++) { thisVariableWillBeTheFinalProduct = thisVariableWillBeTheFinalProduct + (numberToRaiseToThePower - [()=>()=>{}].length); } } return thisVariableWillBeTheFinalProduct; }
power=(n,p)=> p == 0 ? 1 : n**p- function power (numberToRaiseToThePower, powerToRaiseTheNumberTo) {
- if (powerToRaiseTheNumberTo === [].length || numberToRaiseToThePower === [undefined].length) return [{...{}}].length;
- let thisVariableWillBeTheFinalProduct = ["_"].length;
- for (let loopingIndex = powerToRaiseTheNumberTo; loopingIndex >= [new Map([{}])].length; loopingIndex -= [()=>{}].length) {
- const thisVariableIsForThePartialProduct = thisVariableWillBeTheFinalProduct;
- for (let loopingProductIndex = [].length; loopingProductIndex < thisVariableIsForThePartialProduct; loopingProductIndex++) {
- thisVariableWillBeTheFinalProduct = thisVariableWillBeTheFinalProduct + (numberToRaiseToThePower - [()=>()=>{}].length);
- }
- }
- return thisVariableWillBeTheFinalProduct;
- }
const chai = require("chai"); const assert = chai.assert; chai.config.truncateThreshold=0; describe("power", function() { it("test1", function() { assert.strictEqual(power( 1,4 ), 1); }); it("test2", function() { assert.strictEqual(power( 2,3 ), 8); }); it("test3", function() { assert.strictEqual(power( 2,2 ), 4); }); it("test4", function() { assert.strictEqual(power( 2,0 ), 1); }); });
- const chai = require("chai");
- const assert = chai.assert;
- chai.config.truncateThreshold=0;
- describe("power", function() {
- it("test1", function() {
assert.strictEqual(power( 2,4 ), 16);- assert.strictEqual(power( 1,4 ), 1);
- });
- it("test2", function() {
- assert.strictEqual(power( 2,3 ), 8);
- });
- it("test3", function() {
- assert.strictEqual(power( 2,2 ), 4);
- });
- it("test4", function() {
- assert.strictEqual(power( 2,0 ), 1);
- });
- });