functionpow(x, n) { if (n === 0) { return1; } else { return x * pow(x, n - 1); } }
export { pow };
测试文件如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import { pow } from"./app.js"; import"mocha"; import { assert } from"chai"; describe("pow", function () { it(`res is ${pow(2, 3)} or not 8`, function () { assert.equal(pow(2, 3), 8); }); it(`res is ${pow(2, 4)} or not 16`, function () { assert.equal(pow(2, 4), 16); }); it(`res is ${pow(2, 5)} or not 32`, function () { assert.equal(pow(2, 5), 32); }); });