Skip to content

Fix tasks and tests #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Exercises.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions Exercises/1-power.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'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.
// The function may or may not reuse function `power`.
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 };
28 changes: 14 additions & 14 deletions Exercises/1-power.test
Original file line number Diff line number Diff line change
@@ -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],
Expand All @@ -39,8 +39,8 @@
}
},
cases: [
[2, 9],
[2, 8],
[3, 27],
[4, 81],
[4, 64],
]
}]