diff --git a/Exercises.en.md b/Exercises.en.md index 96480ce..1bd1456 100644 --- a/Exercises.en.md +++ b/Exercises.en.md @@ -4,9 +4,10 @@ You can often use more general functions to define more specific functions. -- Define function `power()` which is an alias to `Math.pow()`. -- Implement function `square()` which returns a number to the power of two. -- `bind()` function `power(base, power)` to obtain function `cube(n)`. +- Define function `power(exp, n)`, the same as `Math.pow(n, exp)` but with +reverse order of argumants. +- Implement function `square(n)` which returns a number to the power of two. +- `bind()` function `power(exp, n)` to obtain function `cube(n)`. ## Use closure diff --git a/Exercises/1-power.js b/Exercises/1-power.js index b52b8c8..9a99509 100644 --- a/Exercises/1-power.js +++ b/Exercises/1-power.js @@ -1,6 +1,7 @@ 'use strict'; -// Define function power - an alias to Math.pow(). +// Define function power(exp, n), the same as Math.pow(n, exp) +// but with reverse order of argumants. const power = null; // Implement function `square(n)`, which returns square of its argument. @@ -8,7 +9,7 @@ const power = null; const square = null; // Implement function `cube(n)` using partial application -// The function should return power of three for the given argument. +// The function should return cube of argumant (to the power of three). const cube = null; module.exports = { power, square, cube }; diff --git a/Exercises/1-power.test b/Exercises/1-power.test index c13a04f..1142b91 100644 --- a/Exercises/1-power.test +++ b/Exercises/1-power.test @@ -1,29 +1,29 @@ [{ name: 'power', - length: [32, 32], + length: [24, 50], cases: [ [0, 0, 1], [1, 1, 1], - [1, 2, 1], - [2, 1, 2], + [2, 1, 1], + [1, 2, 2], [2, 2, 4], - [3, 1, 3], - [3, 2, 9], + [1, 3, 3], + [2, 3, 9], [3, 3, 27], - [1, -1, 1], - [1, -2, 1], - [2, -1, 0.5], - [2, -2, 0.25], + [-1, 1, 1], + [-2, 1, 1], + [-1, 2, 0.5], + [-2, 2, 0.25], ], test: power => { const src = power.toString(); - if (src !== 'function pow() { [native code] }') { - throw new Error('Function power expected to be reference to Math.pow'); + if (src === 'function pow() { [native code] }') { + throw new Error('Function power is not expected to be alias of Math.pow'); } } }, { name: 'square', - length: [10, 25], + length: [16, 25], cases: [ [5, 25], [6, 36], @@ -39,8 +39,8 @@ } }, cases: [ - [2, 9], + [2, 8], [3, 27], - [4, 81], + [4, 64], ] }]