Skip to content

Add exercises #1

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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add an Exercises folder. Add autotest
  • Loading branch information
thebladehit committed Nov 7, 2022
commit f4302a3d5f3c5b08c8923ad5ac233136b6699040
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/Recursion.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Exercises/1-showelem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

const deepSum = (array) => {
// use recursion to sum all element of array
// deepSum([1, [2, 3, [4, [5]]], 6, [33]]) = 54
};

module.exports = { deepSum };
19 changes: 19 additions & 0 deletions Exercises/1-showelem.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
({
name: 'deepSum',
length: [150, 230],
cases: [
[[1, 2, 3], 6],
[[0], 0],
[[1, -1, 1], 1],
[[10, -1, -1, -1], 7],
[[1, [2, 3, [4, [5]]], 6, [33]], 54],
],
test(deepSum) {
const src = deepSum.toString();
const numbers = [1, 'string', [12, 3]];
const sum = deepSum(numbers);
if (isNaN(sum)) throw new Error('Do not add string');
if (!src.includes('deepSum(')) throw new Error('Use recursion');
if (!src.includes('return')) throw new Error('Use return');
}
})
8 changes: 8 additions & 0 deletions Exercises/2-powloop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

const pow = (base, power) => {
// use loop to raise a number to a power
// do not use recursion
};

module.exports = { pow };
15 changes: 15 additions & 0 deletions Exercises/2-powloop.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
({
name: 'pow',
length: [110, 140],
cases: [
[2, 1, 2],
[2, 2, 4],
[2, 3, 8],
[2, 10, 1024]
],
test(pow) {
const src = pow.toString();
if (src.includes('pow(')) throw new Error('Do not use recursion');
if (!src.includes('return')) throw new Error('Use return');
}
})
Loading