fix(curriculum): quotes in tests (#18828)

* fix(curriculum): tests quotes

* fix(curriculum): fill seed-teardown

* fix(curriculum): fix tests and remove unneeded seed-teardown
This commit is contained in:
Valeriy
2018-10-20 21:02:47 +03:00
committed by mrugesh mohapatra
parent 96eb124163
commit 79d9012432
1339 changed files with 6499 additions and 5185 deletions

View File

@ -21,11 +21,11 @@ challengeType: 5
```yml
tests:
- text: <code>getFinalOpenedDoors</code> is a function.
testString: 'assert(typeof getFinalOpenedDoors === "function", "<code>getFinalOpenedDoors</code> is a function.");'
testString: assert(typeof getFinalOpenedDoors === 'function', '<code>getFinalOpenedDoors</code> is a function.');
- text: <code>getFinalOpenedDoors</code> should return an array.
testString: 'assert(Array.isArray(getFinalOpenedDoors(100)), "<code>getFinalOpenedDoors</code> should return an array.");'
testString: assert(Array.isArray(getFinalOpenedDoors(100)), '<code>getFinalOpenedDoors</code> should return an array.');
- text: <code>getFinalOpenedDoors</code> did not produce the correct results.
testString: 'assert.deepEqual(getFinalOpenedDoors(100), solution, "<code>getFinalOpenedDoors</code> did not produce the correct results.");'
testString: assert.deepEqual(getFinalOpenedDoors(100), solution, '<code>getFinalOpenedDoors</code> did not produce the correct results.');
```
@ -49,7 +49,7 @@ function getFinalOpenedDoors (numDoors) {
<div id='js-teardown'>
```js
console.info('after the test');
const solution = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100];
```
</div>

View File

@ -35,15 +35,15 @@ challengeType: 5
```yml
tests:
- text: <code>solve24</code> is a function.
testString: 'assert(typeof solve24 === "function", "<code>solve24</code> is a function.");'
testString: assert(typeof solve24 === 'function', '<code>solve24</code> is a function.');
- text: <code>solve24("4878")</code> should return <code>(7-8/8)*4</code> or <code>4*(7-8/8)</code>
testString: 'assert(include(answers[0], solve24(testCases[0])), "<code>solve24("4878")</code> should return <code>(7-8/8)*4</code> or <code>4*(7-8/8)</code>");'
testString: assert(include(answers[0], solve24(testCases[0])), '<code>solve24("4878")</code> should return <code>(7-8/8)*4</code> or <code>4*(7-8/8)</code>');
- text: <code>solve24("1234")</code> should return any arrangement of <code>1*2*3*4</code>
testString: 'assert(include(answers[1], solve24(testCases[1])), "<code>solve24("1234")</code> should return any arrangement of <code>1*2*3*4</code>");'
testString: assert(include(answers[1], solve24(testCases[1])), '<code>solve24("1234")</code> should return any arrangement of <code>1*2*3*4</code>');
- text: <code>solve24("6789")</code> should return <code>(6*8)/(9-7)</code> or <code>(8*6)/(9-7)</code>
testString: 'assert(include(answers[2], solve24(testCases[2])), "<code>solve24("6789")</code> should return <code>(6*8)/(9-7)</code> or <code>(8*6)/(9-7)</code>");'
testString: assert(include(answers[2], solve24(testCases[2])), '<code>solve24("6789")</code> should return <code>(6*8)/(9-7)</code> or <code>(8*6)/(9-7)</code>');
- text: <code>solve24("1127")</code> should return a permutation of <code>(1+7)*(1*2)</code>
testString: 'assert(include(answers[3], solve24(testCases[3])), "<code>solve24("1127")</code> should return a permutation of <code>(1+7)*(1*2)</code>");'
testString: assert(include(answers[3], solve24(testCases[3])), '<code>solve24("1127")</code> should return a permutation of <code>(1+7)*(1*2)</code>');
```
@ -68,7 +68,24 @@ function solve24 (numStr) {
<div id='js-teardown'>
```js
console.info('after the test');
const testCases = [
'4878',
'1234',
'6789',
'1127'
];
const answers = [
['(7-8/8)*4', '4*(7-8/8)', '(4-8+7)*8', '(4+7-8)*8', '(7+4-8)*8', '(7-8+4)*8', '8*(4-8+7)', '8*(4+7-8)', '8*(7+4-8)', '8*(7-8+4)'],
['1*2*3*4', '1*2*4*3', '1*3*2*4', '1*3*4*2', '1*4*2*3', '1*4*3*2', '2*1*3*4', '2*1*4*3', '2*3*1*4', '2*3*4*1', '2*4*3*1', '2*4*1*3', '3*1*2*4', '3*1*4*2', '3*2*1*4', '3*2*4*1', '3*4*1*2', '3*4*2*1', '4*1*2*3', '4*1*3*2', '4*2*1*3', '4*2*3*1', '4*3*1*2', '4*3*2*1', '(1+2+3)*4', '(1+3+2)*4', '(2+1+3)*4', '(2+3+1)*4', '(3+1+2)*4', '(3+2+1)*4', '4*(1+2+3)', '4*(2+1+3)', '4*(2+3+1)', '4*(3+1+2)', '4*(3+2+1)'],
['(6*8)/(9-7)', '(8*6)/(9-7)', '6*8/(9-7)', '8*6/(9-7)'],
['(1+7)*(2+1)', '(1+7)*(1+2)', '(1+2)*(1+7)', '(1+2)*(7+1)', '(2+1)*(1+7)', '(7+1)*(2+1)']
];
function include(ansArr, res) {
const index = ansArr.indexOf(res);
return index >= 0;
}
```
</div>

View File

@ -40,19 +40,19 @@ Task
```yml
tests:
- text: <code>numberOfNames</code> is a function.
testString: 'assert(typeof numberOfNames === "function", "<code>numberOfNames</code> is a function.");'
testString: assert(typeof numberOfNames === 'function', '<code>numberOfNames</code> is a function.');
- text: <code>numberOfNames(5)</code> should equal 7.
testString: 'assert.equal(numberOfNames(5), 7, "<code>numberOfNames(5)</code> should equal 7.");'
testString: assert.equal(numberOfNames(5), 7, '<code>numberOfNames(5)</code> should equal 7.');
- text: <code>numberOfNames(12)</code> should equal 77.
testString: 'assert.equal(numberOfNames(12), 77, "<code>numberOfNames(12)</code> should equal 77.");'
testString: assert.equal(numberOfNames(12), 77, '<code>numberOfNames(12)</code> should equal 77.');
- text: <code>numberOfNames(18)</code> should equal 385.
testString: 'assert.equal(numberOfNames(18), 385, "<code>numberOfNames(18)</code> should equal 385.");'
testString: assert.equal(numberOfNames(18), 385, '<code>numberOfNames(18)</code> should equal 385.');
- text: <code>numberOfNames(23)</code> should equal 1255.
testString: 'assert.equal(numberOfNames(23), 1255, "<code>numberOfNames(23)</code> should equal 1255.");'
testString: assert.equal(numberOfNames(23), 1255, '<code>numberOfNames(23)</code> should equal 1255.');
- text: <code>numberOfNames(42)</code> should equal 53174.
testString: 'assert.equal(numberOfNames(42), 53174, "<code>numberOfNames(42)</code> should equal 53174.");'
testString: assert.equal(numberOfNames(42), 53174, '<code>numberOfNames(42)</code> should equal 53174.');
- text: <code>numberOfNames(123)</code> should equal 2552338241.
testString: 'assert.equal(numberOfNames(123), 2552338241, "<code>numberOfNames(123)</code> should equal 2552338241.");'
testString: assert.equal(numberOfNames(123), 2552338241, '<code>numberOfNames(123)</code> should equal 2552338241.');
```

View File

@ -44,21 +44,21 @@ The function should be case-insensitive.
```yml
tests:
- text: <code>canMakeWord</code> is a function.
testString: 'assert(typeof canMakeWord === "function", "<code>canMakeWord</code> is a function.");'
testString: assert(typeof canMakeWord === 'function', '<code>canMakeWord</code> is a function.');
- text: <code>canMakeWord</code> should return a boolean.
testString: 'assert(typeof canMakeWord("hi") === "boolean", "<code>canMakeWord</code> should return a boolean.");'
testString: assert(typeof canMakeWord('hi') === 'boolean', '<code>canMakeWord</code> should return a boolean.');
- text: <code>canMakeWord("bark")</code> should return true.
testString: 'assert(canMakeWord(words[0]), "<code>canMakeWord("bark")</code> should return true.");'
testString: assert(canMakeWord(words[0]), '<code>canMakeWord("bark")</code> should return true.');
- text: <code>canMakeWord("BooK")</code> should return false.
testString: 'assert(!canMakeWord(words[1]), "<code>canMakeWord("BooK")</code> should return false.");'
testString: assert(!canMakeWord(words[1]), '<code>canMakeWord("BooK")</code> should return false.');
- text: <code>canMakeWord("TReAT")</code> should return true.
testString: 'assert(canMakeWord(words[2]), "<code>canMakeWord("TReAT")</code> should return true.");'
testString: assert(canMakeWord(words[2]), '<code>canMakeWord("TReAT")</code> should return true.');
- text: <code>canMakeWord("COMMON")</code> should return false.
testString: 'assert(!canMakeWord(words[3]), "<code>canMakeWord("COMMON")</code> should return false.");'
testString: assert(!canMakeWord(words[3]), '<code>canMakeWord("COMMON")</code> should return false.');
- text: <code>canMakeWord("squAD")</code> should return true.
testString: 'assert(canMakeWord(words[4]), "<code>canMakeWord("squAD")</code> should return true.");'
testString: assert(canMakeWord(words[4]), '<code>canMakeWord("squAD")</code> should return true.');
- text: <code>canMakeWord("conFUSE")</code> should return true.
testString: 'assert(canMakeWord(words[5]), "<code>canMakeWord("conFUSE")</code> should return true.");'
testString: assert(canMakeWord(words[5]), '<code>canMakeWord("conFUSE")</code> should return true.');
```
@ -82,7 +82,7 @@ function canMakeWord (word) {
<div id='js-teardown'>
```js
console.info('after the test');
const words = ['bark', 'BooK', 'TReAT', 'COMMON', 'squAD', 'conFUSE'];
```
</div>

View File

@ -28,13 +28,13 @@ challengeType: 5
```yml
tests:
- text: <code>getDPA</code> is a function.
testString: 'assert(typeof getDPA === "function", "<code>getDPA</code> is a function.");'
testString: assert(typeof getDPA === 'function', '<code>getDPA</code> is a function.');
- text: <code>getDPA</code> should return an array.
testString: 'assert(Array.isArray(getDPA(100)), "<code>getDPA</code> should return an array.");'
testString: assert(Array.isArray(getDPA(100)), '<code>getDPA</code> should return an array.');
- text: <code>getDPA</code> return value should have a length of 3.
testString: 'assert(getDPA(100).length === 3, "<code>getDPA</code> return value should have a length of 3.");'
- text: '<code>getDPA(20000)</code> should equal [15043, 4, 4953]'
testString: 'assert.deepEqual(getDPA(20000), solution, "<code>getDPA(20000)</code> should equal [15043, 4, 4953]");'
testString: assert(getDPA(100).length === 3, '<code>getDPA</code> return value should have a length of 3.');
- text: <code>getDPA(20000)</code> should equal [15043, 4, 4953]
testString: assert.deepEqual(getDPA(20000), solution, '<code>getDPA(20000)</code> should equal [15043, 4, 4953]');
```
@ -58,7 +58,7 @@ function getDPA (num) {
<div id='js-teardown'>
```js
console.info('after the test');
const solution = [15043, 4, 4953];
```
</div>

View File

@ -24,13 +24,13 @@ challengeType: 5
```yml
tests:
- text: <code>accumulator</code> is a function.
testString: 'assert(typeof accumulator === "function", "<code>accumulator</code> is a function.");'
testString: assert(typeof accumulator === 'function', '<code>accumulator</code> is a function.');
- text: <code>accumulator(0)</code> should return a function.
testString: 'assert(typeof accumulator(0) === "function", "<code>accumulator(0)</code> should return a function.");'
testString: assert(typeof accumulator(0) === 'function', '<code>accumulator(0)</code> should return a function.');
- text: <code>accumulator(0)(2)</code> should return a number.
testString: 'assert(typeof accumulator(0)(2) === "number", "<code>accumulator(0)(2)</code> should return a number.");'
- text: 'Passing in the values 3, -4, 1.5, and 5 should return 5.5.'
testString: 'assert(testFn(5) === 5.5, "Passing in the values 3, -4, 1.5, and 5 should return 5.5.");'
testString: assert(typeof accumulator(0)(2) === 'number', '<code>accumulator(0)(2)</code> should return a number.');
- text: Passing in the values 3, -4, 1.5, and 5 should return 5.5.
testString: assert(testFn(5) === 5.5, 'Passing in the values 3, -4, 1.5, and 5 should return 5.5.');
```
@ -54,7 +54,11 @@ function accumulator (sum) {
<div id='js-teardown'>
```js
console.info('after the test');
const testFn = typeof accumulator(3) === 'function' && accumulator(3);
if (testFn) {
testFn(-4);
testFn(1.5);
}
```
</div>

View File

@ -28,15 +28,15 @@ $$A(m, n) =
```yml
tests:
- text: <code>ack</code> is a function.
testString: 'assert(typeof ack === "function", "<code>ack</code> is a function.");'
- text: '<code>ack(0, 0)</code> should return 1.'
testString: 'assert(ack(0, 0) === 1, "<code>ack(0, 0)</code> should return 1.");'
- text: '<code>ack(1, 1)</code> should return 3.'
testString: 'assert(ack(1, 1) === 3, "<code>ack(1, 1)</code> should return 3.");'
- text: '<code>ack(2, 5)</code> should return 13.'
testString: 'assert(ack(2, 5) === 13, "<code>ack(2, 5)</code> should return 13.");'
- text: '<code>ack(3, 3)</code> should return 61.'
testString: 'assert(ack(3, 3) === 61, "<code>ack(3, 3)</code> should return 61.");'
testString: assert(typeof ack === 'function', '<code>ack</code> is a function.');
- text: <code>ack(0, 0)</code> should return 1.
testString: assert(ack(0, 0) === 1, '<code>ack(0, 0)</code> should return 1.');
- text: <code>ack(1, 1)</code> should return 3.
testString: assert(ack(1, 1) === 3, '<code>ack(1, 1)</code> should return 3.');
- text: <code>ack(2, 5)</code> should return 13.
testString: assert(ack(2, 5) === 13, '<code>ack(2, 5)</code> should return 13.');
- text: <code>ack(3, 3)</code> should return 61.
testString: assert(ack(3, 3) === 61, '<code>ack(3, 3)</code> should return 61.');
```

View File

@ -40,13 +40,13 @@ It is not a requirement to add separating characters between or around columns.
```yml
tests:
- text: <code>formatText</code> is a function.
testString: 'assert(typeof formatText === "function", "<code>formatText</code> is a function.");'
testString: assert(typeof formatText === 'function', '<code>formatText</code> is a function.');
- text: '<code>formatText</code> with the above input and "right" justification should produce the following: '
testString: 'assert.strictEqual(formatText(testInput, "right"), rightAligned, "<code>formatText</code> with the above input and "right" justification should produce the following: ");'
testString: 'assert.strictEqual(formatText(testInput, ''right''), rightAligned, ''<code>formatText</code> with the above input and "right" justification should produce the following: '');'
- text: '<code>formatText</code> with the above input and "left" justification should produce the following: '
testString: 'assert.strictEqual(formatText(testInput, "left"), leftAligned, "<code>formatText</code> with the above input and "left" justification should produce the following: ");'
testString: 'assert.strictEqual(formatText(testInput, ''left''), leftAligned, ''<code>formatText</code> with the above input and "left" justification should produce the following: '');'
- text: '<code>formatText</code> with the above input and "center" justification should produce the following: '
testString: 'assert.strictEqual(formatText(testInput, "center"), centerAligned, "<code>formatText</code> with the above input and "center" justification should produce the following: ");'
testString: 'assert.strictEqual(formatText(testInput, ''center''), centerAligned, ''<code>formatText</code> with the above input and "center" justification should produce the following: '');'
```
@ -83,9 +83,52 @@ function formatText (input, justification) {
<div id='js-teardown'>
```js
console.info('after the test');
```
const testInput = [
'Given$a$text$file$of$many$lines',
'where$fields$within$a$line$',
'are$delineated$by$a$single$\"dollar\"$character',
'write$a$program',
'that$aligns$each$column$of$fields$',
'by$ensuring$that$words$in$each$',
'column$are$separated$by$at$least$one$space.',
'Further,$allow$for$each$word$in$a$column$to$be$either$left$',
'justified,$right$justified',
'or$center$justified$within$its$column.'
];
const rightAligned = ' Given a text file of many lines\n' +
' where fields within a line \n' +
' are delineated by a single "dollar" character\n' +
' write a program\n' +
' that aligns each column of fields \n' +
' by ensuring that words in each \n' +
' column are separated by at least one space.\n' +
' Further, allow for each word in a column to be either left \n' +
'justified, right justified\n' +
' or center justified within its column.';
const leftAligned = 'Given a text file of many lines \n' +
'where fields within a line \n' +
'are delineated by a single "dollar" character\n' +
'write a program \n' +
'that aligns each column of fields \n' +
'by ensuring that words in each \n' +
'column are separated by at least one space.\n' +
'Further, allow for each word in a column to be either left \n' +
'justified, right justified\n' +
'or center justified within its column. ';
const centerAligned = ' Given a text file of many lines \n' +
' where fields within a line \n' +
' are delineated by a single \"dollar\" character\n' +
' write a program \n' +
' that aligns each column of fields \n' +
' by ensuring that words in each \n' +
' column are separated by at least one space.\n' +
' Further, allow for each word in a column to be either left \n' +
'justified, right justified\n' +
' or center justified within its column. ';
```
</div>
</section>
@ -131,10 +174,10 @@ function formatText (input, justification) {
left = ' '.repeat(Math.floor(diff));
right = ' '.repeat(Math.ceil(diff));
if (justification === 'left') {
right += left; left = ";
right += left; left = '';
}
if (justification === 'right') {
left += right; right = ";
left += right; right = '';
}
input[y][x] = left + input[y][x] + right;
}

View File

@ -30,13 +30,13 @@ Related tasks
```yml
tests:
- text: <code>amicablePairsUpTo</code> is a function.
testString: 'assert(typeof amicablePairsUpTo === "function", "<code>amicablePairsUpTo</code> is a function.");'
- text: '<code>amicablePairsUpTo(300)</code> should return <code>[[220,284]]</code>.'
testString: 'assert.deepEqual(amicablePairsUpTo(300), answer300, "<code>amicablePairsUpTo(300)</code> should return <code>[[220,284]]</code>.");'
- text: '<code>amicablePairsUpTo(3000)</code> should return <code>[[220,284],[1184,1210],[2620,2924]]</code>.'
testString: 'assert.deepEqual(amicablePairsUpTo(3000), answer3000, "<code>amicablePairsUpTo(3000)</code> should return <code>[[220,284],[1184,1210],[2620,2924]]</code>.");'
- text: '<code>amicablePairsUpTo(20000)</code> should return <code>[[220,284],[1184,1210],[2620,2924],[5020,5564],[6232,6368],[10744,10856],[12285,14595],[17296,18416]]</code>.'
testString: 'assert.deepEqual(amicablePairsUpTo(20000), answer20000, "<code>amicablePairsUpTo(20000)</code> should return <code>[[220,284],[1184,1210],[2620,2924],[5020,5564],[6232,6368],[10744,10856],[12285,14595],[17296,18416]]</code>.");'
testString: assert(typeof amicablePairsUpTo === 'function', '<code>amicablePairsUpTo</code> is a function.');
- text: <code>amicablePairsUpTo(300)</code> should return <code>[[220,284]]</code>.
testString: assert.deepEqual(amicablePairsUpTo(300), answer300, '<code>amicablePairsUpTo(300)</code> should return <code>[[220,284]]</code>.');
- text: <code>amicablePairsUpTo(3000)</code> should return <code>[[220,284],[1184,1210],[2620,2924]]</code>.
testString: assert.deepEqual(amicablePairsUpTo(3000), answer3000, '<code>amicablePairsUpTo(3000)</code> should return <code>[[220,284],[1184,1210],[2620,2924]]</code>.');
- text: <code>amicablePairsUpTo(20000)</code> should return <code>[[220,284],[1184,1210],[2620,2924],[5020,5564],[6232,6368],[10744,10856],[12285,14595],[17296,18416]]</code>.
testString: assert.deepEqual(amicablePairsUpTo(20000), answer20000, '<code>amicablePairsUpTo(20000)</code> should return <code>[[220,284],[1184,1210],[2620,2924],[5020,5564],[6232,6368],[10744,10856],[12285,14595],[17296,18416]]</code>.');
```
@ -61,7 +61,22 @@ function amicablePairsUpTo (maxNum) {
<div id='js-teardown'>
```js
console.info('after the test');
const answer300 = [[220, 284]];
const answer3000 = [
[220, 284],
[1184, 1210],
[2620, 2924]
];
const answer20000 = [
[220, 284],
[1184, 1210],
[2620, 2924],
[5020, 5564],
[6232, 6368],
[10744, 10856],
[12285, 14595],
[17296, 18416]
];
```
</div>

View File

@ -20,11 +20,11 @@ challengeType: 5
```yml
tests:
- text: <code>mode</code> is a function.
testString: 'assert(typeof mode === "function", "<code>mode</code> is a function.");'
- text: '<code>mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17])</code> should equal <code>[6]</code>'
testString: 'assert.deepEqual(mode(arr1), [6], "<code>mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17])</code> should equal <code>[6]</code>");'
- text: '<code>mode([1, 2, 4, 4, 1])</code> should equal <code>[1, 4]</code>.'
testString: 'assert.deepEqual(mode(arr2).sort(), [1, 4], "<code>mode([1, 2, 4, 4, 1])</code> should equal <code>[1, 4]</code>.");'
testString: assert(typeof mode === 'function', '<code>mode</code> is a function.');
- text: <code>mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17])</code> should equal <code>[6]</code>
testString: assert.deepEqual(mode(arr1), [6], '<code>mode([1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17])</code> should equal <code>[6]</code>');
- text: <code>mode([1, 2, 4, 4, 1])</code> should equal <code>[1, 4]</code>.
testString: assert.deepEqual(mode(arr2).sort(), [1, 4], '<code>mode([1, 2, 4, 4, 1])</code> should equal <code>[1, 4]</code>.');
```
@ -49,7 +49,8 @@ function mode (arr) {
<div id='js-teardown'>
```js
console.info('after the test');
const arr1 = [1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17];
const arr2 = [1, 2, 4, 4, 1];
```
</div>

View File

@ -32,9 +32,9 @@ challengeType: 5
```yml
tests:
- text: <code>pythagoreanMeans</code> is a function.
testString: 'assert(typeof pythagoreanMeans === "function", "<code>pythagoreanMeans</code> is a function.");'
- text: '<code>pythagoreanMeans([1, 2, ..., 10])</code> should equal the same output above.'
testString: 'assert.deepEqual(pythagoreanMeans(range1), answer1, "<code>pythagoreanMeans([1, 2, ..., 10])</code> should equal the same output above.");'
testString: assert(typeof pythagoreanMeans === 'function', '<code>pythagoreanMeans</code> is a function.');
- text: <code>pythagoreanMeans([1, 2, ..., 10])</code> should equal the same output above.
testString: assert.deepEqual(pythagoreanMeans(range1), answer1, '<code>pythagoreanMeans([1, 2, ..., 10])</code> should equal the same output above.');
```
@ -58,7 +58,16 @@ function pythagoreanMeans (rangeArr) {
<div id='js-teardown'>
```js
console.info('after the test');
const range1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const answer1 = {
values: {
Arithmetic: 5.5,
Geometric: 4.528728688116765,
Harmonic: 3.414171521474055
},
test: 'is A >= G >= H ? yes'
};
```
</div>

View File

@ -22,9 +22,9 @@ challengeType: 5
```yml
tests:
- text: <code>rms</code> is a function.
testString: 'assert(typeof rms === "function", "<code>rms</code> is a function.");'
- text: '<code>rms([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])</code> should equal <code>6.2048368229954285</code>.'
testString: 'assert.equal(rms(arr1), answer1, "<code>rms([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])</code> should equal <code>6.2048368229954285</code>.");'
testString: assert(typeof rms === 'function', '<code>rms</code> is a function.');
- text: <code>rms([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])</code> should equal <code>6.2048368229954285</code>.
testString: assert.equal(rms(arr1), answer1, '<code>rms([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])</code> should equal <code>6.2048368229954285</code>.');
```
@ -48,7 +48,8 @@ function rms (arr) {
<div id='js-teardown'>
```js
console.info('after the test');
const arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const answer1 = 6.2048368229954285;
```
</div>

View File

@ -25,9 +25,9 @@ challengeType: 5
```yml
tests:
- text: <code>babbage</code> is a function.
testString: 'assert(typeof babbage === "function", "<code>babbage</code> is a function.");'
- text: '<code>babbage(99736, 269696)</code> should not return 99736 (there is a smaller answer).'
testString: 'assert.equal(babbage(babbageAns, endDigits), answer, "<code>babbage(99736, 269696)</code> should not return 99736 (there is a smaller answer).");'
testString: assert(typeof babbage === 'function', '<code>babbage</code> is a function.');
- text: <code>babbage(99736, 269696)</code> should not return 99736 (there is a smaller answer).
testString: assert.equal(babbage(babbageAns, endDigits), answer, '<code>babbage(99736, 269696)</code> should not return 99736 (there is a smaller answer).');
```
@ -52,7 +52,9 @@ function babbage (babbageNum, endDigits) {
<div id='js-teardown'>
```js
console.info('after the test');
const babbageAns = 99736;
const endDigits = 269696;
const answer = 25264;
```
</div>
@ -66,7 +68,7 @@ console.info('after the test');
```js
function babbage (babbageAns, endDigits) {
const babbageNum = Math.pow(babbageAns, 2);
const babbageStartDigits = parseInt(babbageNum.toString().replace('269696', "));
const babbageStartDigits = parseInt(babbageNum.toString().replace('269696', ''));
let answer = 99736;
// count down from this answer and save any sqrt int result. return lowest one

View File

@ -28,43 +28,43 @@ Examples:
```yml
tests:
- text: <code>isBalanced</code> is a function.
testString: 'assert(typeof isBalanced === "function", "<code>isBalanced</code> is a function.");'
- text: '<code>isBalanced("[]")</code> should return true.'
testString: 'assert(isBalanced(testCases[0]), "<code>isBalanced("[]")</code> should return true.");'
- text: '<code>isBalanced("]][[[][][][]][")</code> should return false.'
testString: 'assert(!isBalanced(testCases[1]), "<code>isBalanced("]][[[][][][]][")</code> should return false.");'
- text: '<code>isBalanced("[][[[[][][[[]]]]]]")</code> should return true.'
testString: 'assert(isBalanced(testCases[2]), "<code>isBalanced("[][[[[][][[[]]]]]]")</code> should return true.");'
- text: '<code>isBalanced("][")</code> should return true.'
testString: 'assert(!isBalanced(testCases[3]), "<code>isBalanced("][")</code> should return true.");'
- text: '<code>isBalanced("[[[]]]][[]")</code> should return true.'
testString: 'assert(!isBalanced(testCases[4]), "<code>isBalanced("[[[]]]][[]")</code> should return true.");'
- text: '<code>isBalanced("][[]")</code> should return true.'
testString: 'assert(!isBalanced(testCases[5]), "<code>isBalanced("][[]")</code> should return true.");'
- text: '<code>isBalanced("][[][]][[[]]")</code> should return true.'
testString: 'assert(!isBalanced(testCases[6]), "<code>isBalanced("][[][]][[[]]")</code> should return true.");'
- text: '<code>isBalanced("[[][]]][")</code> should return true.'
testString: 'assert(!isBalanced(testCases[7]), "<code>isBalanced("[[][]]][")</code> should return true.");'
- text: '<code>isBalanced("[[[]]][[]]]][][[")</code> should return true.'
testString: 'assert(!isBalanced(testCases[8]), "<code>isBalanced("[[[]]][[]]]][][[")</code> should return true.");'
- text: '<code>isBalanced("[]][[]]][[[[][]]")</code> should return true.'
testString: 'assert(!isBalanced(testCases[9]), "<code>isBalanced("[]][[]]][[[[][]]")</code> should return true.");'
- text: '<code>isBalanced("][]][[][")</code> should return true.'
testString: 'assert(!isBalanced(testCases[10]), "<code>isBalanced("][]][[][")</code> should return true.");'
- text: '<code>isBalanced("[[]][[][]]")</code> should return true.'
testString: 'assert(isBalanced(testCases[11]), "<code>isBalanced("[[]][[][]]")</code> should return true.");'
- text: '<code>isBalanced("[[]]")</code> should return true.'
testString: 'assert(isBalanced(testCases[12]), "<code>isBalanced("[[]]")</code> should return true.");'
- text: '<code>isBalanced("]][]][[]][[[")</code> should return true.'
testString: 'assert(!isBalanced(testCases[13]), "<code>isBalanced("]][]][[]][[[")</code> should return true.");'
- text: '<code>isBalanced("][]][][[")</code> should return true.'
testString: 'assert(!isBalanced(testCases[14]), "<code>isBalanced("][]][][[")</code> should return true.");'
- text: '<code>isBalanced("][][")</code> should return true.'
testString: 'assert(!isBalanced(testCases[15]), "<code>isBalanced("][][")</code> should return true.");'
- text: '<code>isBalanced("[[]]][][][[]][")</code> should return true.'
testString: 'assert(!isBalanced(testCases[16]), "<code>isBalanced("[[]]][][][[]][")</code> should return true.");'
testString: assert(typeof isBalanced === 'function', '<code>isBalanced</code> is a function.');
- text: <code>isBalanced("[]")</code> should return true.
testString: assert(isBalanced(testCases[0]), '<code>isBalanced("[]")</code> should return true.');
- text: <code>isBalanced("]][[[][][][]][")</code> should return false.
testString: assert(!isBalanced(testCases[1]), '<code>isBalanced("]][[[][][][]][")</code> should return false.');
- text: <code>isBalanced("[][[[[][][[[]]]]]]")</code> should return true.
testString: assert(isBalanced(testCases[2]), '<code>isBalanced("[][[[[][][[[]]]]]]")</code> should return true.');
- text: <code>isBalanced("][")</code> should return true.
testString: assert(!isBalanced(testCases[3]), '<code>isBalanced("][")</code> should return true.');
- text: <code>isBalanced("[[[]]]][[]")</code> should return true.
testString: assert(!isBalanced(testCases[4]), '<code>isBalanced("[[[]]]][[]")</code> should return true.');
- text: <code>isBalanced("][[]")</code> should return true.
testString: assert(!isBalanced(testCases[5]), '<code>isBalanced("][[]")</code> should return true.');
- text: <code>isBalanced("][[][]][[[]]")</code> should return true.
testString: assert(!isBalanced(testCases[6]), '<code>isBalanced("][[][]][[[]]")</code> should return true.');
- text: <code>isBalanced("[[][]]][")</code> should return true.
testString: assert(!isBalanced(testCases[7]), '<code>isBalanced("[[][]]][")</code> should return true.');
- text: <code>isBalanced("[[[]]][[]]]][][[")</code> should return true.
testString: assert(!isBalanced(testCases[8]), '<code>isBalanced("[[[]]][[]]]][][[")</code> should return true.');
- text: <code>isBalanced("[]][[]]][[[[][]]")</code> should return true.
testString: assert(!isBalanced(testCases[9]), '<code>isBalanced("[]][[]]][[[[][]]")</code> should return true.');
- text: <code>isBalanced("][]][[][")</code> should return true.
testString: assert(!isBalanced(testCases[10]), '<code>isBalanced("][]][[][")</code> should return true.');
- text: <code>isBalanced("[[]][[][]]")</code> should return true.
testString: assert(isBalanced(testCases[11]), '<code>isBalanced("[[]][[][]]")</code> should return true.');
- text: <code>isBalanced("[[]]")</code> should return true.
testString: assert(isBalanced(testCases[12]), '<code>isBalanced("[[]]")</code> should return true.');
- text: <code>isBalanced("]][]][[]][[[")</code> should return true.
testString: assert(!isBalanced(testCases[13]), '<code>isBalanced("]][]][[]][[[")</code> should return true.');
- text: <code>isBalanced("][]][][[")</code> should return true.
testString: assert(!isBalanced(testCases[14]), '<code>isBalanced("][]][][[")</code> should return true.');
- text: <code>isBalanced("][][")</code> should return true.
testString: assert(!isBalanced(testCases[15]), '<code>isBalanced("][][")</code> should return true.');
- text: <code>isBalanced("[[]]][][][[]][")</code> should return true.
testString: assert(!isBalanced(testCases[16]), '<code>isBalanced("[[]]][][][[]][")</code> should return true.');
- text: <code>isBalanced("")</code> should return true.
testString: 'assert(isBalanced(testCases[17]), "<code>isBalanced("")</code> should return true.");'
testString: assert(isBalanced(testCases[17]), '<code>isBalanced("")</code> should return true.');
```
@ -89,7 +89,26 @@ function isBalanced (str) {
<div id='js-teardown'>
```js
console.info('after the test');
const testCases = [
'[]',
']][[[][][][]][',
'[][[[[][][[[]]]]]]',
'][',
'[[[]]]][[]',
'][[]',
'][[][]][[[]]',
'[[][]]][',
'[[[]]][[]]]][][[',
'[]][[]]][[[[][]]',
'][]][[][',
'[[]][[][]]',
'[[]]',
']][]][[]][[[',
'][]][][[',
'][][',
'[[]]][][][[]][',
''
];
```
</div>
@ -102,12 +121,12 @@ console.info('after the test');
```js
function isBalanced (str) {
if (str === ") return true;
if (str === '') return true;
let a = str;
let b;
do {
b = a;
a = a.replace(/\[\]/g, ");
a = a.replace(/\[\]/g, '');
} while (a !== b);
return !a;
}

View File

@ -41,17 +41,17 @@ Ref:
```yml
tests:
- text: <code>getCircles</code> is a function.
testString: 'assert(typeof getCircles === "function", "<code>getCircles</code> is a function.");'
- text: '<code>getCircles([0.1234, 0.9876], [0.8765, 0.2345], 2.0)</code> should return <code>[[1.8631, 1.9742], [-0.8632, -0.7521]]</code>.'
testString: 'assert.deepEqual(getCircles(...testCases[0]), answers[0], "<code>getCircles([0.1234, 0.9876], [0.8765, 0.2345], 2.0)</code> should return <code>[[1.8631, 1.9742], [-0.8632, -0.7521]]</code>.");'
- text: '<code>getCircles([0.0000, 2.0000], [0.0000, 0.0000], 1.0)</code> should return <code>[0, 1]</code>'
testString: 'assert.deepEqual(getCircles(...testCases[1]), answers[1], "<code>getCircles([0.0000, 2.0000], [0.0000, 0.0000], 1.0)</code> should return <code>[0, 1]</code>");'
- text: '<code>getCircles([0.1234, 0.9876], [0.1234, 0.9876], 2.0)</code> should return <code>Coincident point. Infinite solutions</code>'
testString: 'assert.deepEqual(getCircles(...testCases[2]), answers[2], "<code>getCircles([0.1234, 0.9876], [0.1234, 0.9876], 2.0)</code> should return <code>Coincident point. Infinite solutions</code>");'
- text: '<code>getCircles([0.1234, 0.9876], [0.8765, 0.2345], 0.5)</code> should return <code>No intersection. Points further apart than circle diameter</code>'
testString: 'assert.deepEqual(getCircles(...testCases[3]), answers[3], "<code>getCircles([0.1234, 0.9876], [0.8765, 0.2345], 0.5)</code> should return <code>No intersection. Points further apart than circle diameter</code>");'
- text: '<code>getCircles([0.1234, 0.9876], [0.1234, 0.9876], 0.0)</code> should return <code>Radius Zero</code>'
testString: 'assert.deepEqual(getCircles(...testCases[4]), answers[4], "<code>getCircles([0.1234, 0.9876], [0.1234, 0.9876], 0.0)</code> should return <code>Radius Zero</code>");'
testString: assert(typeof getCircles === 'function', '<code>getCircles</code> is a function.');
- text: <code>getCircles([0.1234, 0.9876], [0.8765, 0.2345], 2.0)</code> should return <code>[[1.8631, 1.9742], [-0.8632, -0.7521]]</code>.
testString: assert.deepEqual(getCircles(...testCases[0]), answers[0], '<code>getCircles([0.1234, 0.9876], [0.8765, 0.2345], 2.0)</code> should return <code>[[1.8631, 1.9742], [-0.8632, -0.7521]]</code>.');
- text: <code>getCircles([0.0000, 2.0000], [0.0000, 0.0000], 1.0)</code> should return <code>[0, 1]</code>
testString: assert.deepEqual(getCircles(...testCases[1]), answers[1], '<code>getCircles([0.0000, 2.0000], [0.0000, 0.0000], 1.0)</code> should return <code>[0, 1]</code>');
- text: <code>getCircles([0.1234, 0.9876], [0.1234, 0.9876], 2.0)</code> should return <code>Coincident point. Infinite solutions</code>
testString: assert.deepEqual(getCircles(...testCases[2]), answers[2], '<code>getCircles([0.1234, 0.9876], [0.1234, 0.9876], 2.0)</code> should return <code>Coincident point. Infinite solutions</code>');
- text: <code>getCircles([0.1234, 0.9876], [0.8765, 0.2345], 0.5)</code> should return <code>No intersection. Points further apart than circle diameter</code>
testString: assert.deepEqual(getCircles(...testCases[3]), answers[3], '<code>getCircles([0.1234, 0.9876], [0.8765, 0.2345], 0.5)</code> should return <code>No intersection. Points further apart than circle diameter</code>');
- text: <code>getCircles([0.1234, 0.9876], [0.1234, 0.9876], 0.0)</code> should return <code>Radius Zero</code>
testString: assert.deepEqual(getCircles(...testCases[4]), answers[4], '<code>getCircles([0.1234, 0.9876], [0.1234, 0.9876], 0.0)</code> should return <code>Radius Zero</code>');
```
@ -76,7 +76,20 @@ function getCircles (...args) {
<div id='js-teardown'>
```js
console.info('after the test');
const testCases = [
[[0.1234, 0.9876], [0.8765, 0.2345], 2.0],
[[0.0000, 2.0000], [0.0000, 0.0000], 1.0],
[[0.1234, 0.9876], [0.1234, 0.9876], 2.0],
[[0.1234, 0.9876], [0.8765, 0.2345], 0.5],
[[0.1234, 0.9876], [0.1234, 0.9876], 0.0]
];
const answers = [
[[1.8631, 1.9742], [-0.8632, -0.7521]],
[0, 1],
'Coincident point. Infinite solutions',
'No intersection. Points further apart than circle diameter',
'Radius Zero'
];
```
</div>

View File

@ -80,15 +80,15 @@ References and further readings:
```yml
tests:
- text: <code>getClosestPair</code> is a function.
testString: 'assert(typeof getClosestPair === "function", "<code>getClosestPair</code> is a function.");'
testString: assert(typeof getClosestPair === 'function', '<code>getClosestPair</code> is a function.');
- text: Distance should be the following.
testString: 'assert.equal(getClosestPair(points1).distance, answer1.distance, "Distance should be the following.");'
testString: assert.equal(getClosestPair(points1).distance, answer1.distance, 'Distance should be the following.');
- text: Points should be the following.
testString: 'assert.deepEqual(JSON.parse(JSON.stringify(getClosestPair(points1))).pair, answer1.pair, "Points should be the following.");'
testString: assert.deepEqual(JSON.parse(JSON.stringify(getClosestPair(points1))).pair, answer1.pair, 'Points should be the following.');
- text: Distance should be the following.
testString: 'assert.equal(getClosestPair(points2).distance, answer2.distance, "Distance should be the following.");'
testString: assert.equal(getClosestPair(points2).distance, answer2.distance, 'Distance should be the following.');
- text: Points should be the following.
testString: 'assert.deepEqual(JSON.parse(JSON.stringify(getClosestPair(points2))).pair, answer2.pair, "Points should be the following.");'
testString: assert.deepEqual(JSON.parse(JSON.stringify(getClosestPair(points2))).pair, answer2.pair, 'Points should be the following.');
```
@ -124,7 +124,107 @@ function getClosestPair (pointsArr) {
<div id='js-teardown'>
```js
console.info('after the test');
const points1 = [
new Point(0.748501, 4.09624),
new Point(3.00302, 5.26164),
new Point(3.61878, 9.52232),
new Point(7.46911, 4.71611),
new Point(5.7819, 2.69367),
new Point(2.34709, 8.74782),
new Point(2.87169, 5.97774),
new Point(6.33101, 0.463131),
new Point(7.46489, 4.6268),
new Point(1.45428, 0.087596)
];
const points2 = [
new Point(37100, 13118),
new Point(37134, 1963),
new Point(37181, 2008),
new Point(37276, 21611),
new Point(37307, 9320)
];
const answer1 = {
distance: 0.0894096443343775,
pair: [
{
x: 7.46489,
y: 4.6268
},
{
x: 7.46911,
y: 4.71611
}
]
};
const answer2 = {
distance: 65.06919393998976,
pair: [
{
x: 37134,
y: 1963
},
{
x: 37181,
y: 2008
}
]
};
const benchmarkPoints = [
new Point(16909, 54699),
new Point(14773, 61107),
new Point(95547, 45344),
new Point(95951, 17573),
new Point(5824, 41072),
new Point(8769, 52562),
new Point(21182, 41881),
new Point(53226, 45749),
new Point(68180, 887),
new Point(29322, 44017),
new Point(46817, 64975),
new Point(10501, 483),
new Point(57094, 60703),
new Point(23318, 35472),
new Point(72452, 88070),
new Point(67775, 28659),
new Point(19450, 20518),
new Point(17314, 26927),
new Point(98088, 11164),
new Point(25050, 56835),
new Point(8364, 6892),
new Point(37868, 18382),
new Point(23723, 7701),
new Point(55767, 11569),
new Point(70721, 66707),
new Point(31863, 9837),
new Point(49358, 30795),
new Point(13041, 39745),
new Point(59635, 26523),
new Point(25859, 1292),
new Point(1551, 53890),
new Point(70316, 94479),
new Point(48549, 86338),
new Point(46413, 92747),
new Point(27186, 50426),
new Point(27591, 22655),
new Point(10905, 46153),
new Point(40408, 84202),
new Point(52821, 73520),
new Point(84865, 77388),
new Point(99819, 32527),
new Point(34404, 75657),
new Point(78457, 96615),
new Point(42140, 5564),
new Point(62175, 92342),
new Point(54958, 67112),
new Point(4092, 19709),
new Point(99415, 60298),
new Point(51090, 52158),
new Point(48953, 58567)
];
```
</div>

View File

@ -35,11 +35,11 @@ Example:
```yml
tests:
- text: <code>combinations</code> is a function.
testString: 'assert(typeof combinations === "function", "<code>combinations</code> is a function.");'
- text: '<code>combinations(3, 5)</code> should return <code>[[0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 2, 3], [0, 2, 4], [0, 3, 4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]</code>.'
testString: 'assert.deepEqual(combinations(testInput1[0], testInput1[1]), testOutput1, "<code>combinations(3, 5)</code> should return <code>[[0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 2, 3], [0, 2, 4], [0, 3, 4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]</code>.");'
- text: '<code>combinations(4, 6)</code> should return <code>[[0,1,2,3], [0,1,2,4], [0,1,2,5], [0,1,3,4], [0,1,3,5], [0,1,4,5], [0,2,3,4], [0,2,3,5], [0,2,4,5], [0,3,4,5], [1,2,3,4], [1,2,3,5], [1,2,4,5], [1,3,4,5], [2,3,4,5]]</code>'
testString: 'assert.deepEqual(combinations(testInput2[0], testInput2[1]), testOutput2, "<code>combinations(4, 6)</code> should return <code>[[0,1,2,3], [0,1,2,4], [0,1,2,5], [0,1,3,4], [0,1,3,5], [0,1,4,5], [0,2,3,4], [0,2,3,5], [0,2,4,5], [0,3,4,5], [1,2,3,4], [1,2,3,5], [1,2,4,5], [1,3,4,5], [2,3,4,5]]</code>");'
testString: assert(typeof combinations === 'function', '<code>combinations</code> is a function.');
- text: <code>combinations(3, 5)</code> should return <code>[[0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 2, 3], [0, 2, 4], [0, 3, 4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]</code>.
testString: assert.deepEqual(combinations(testInput1[0], testInput1[1]), testOutput1, '<code>combinations(3, 5)</code> should return <code>[[0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 2, 3], [0, 2, 4], [0, 3, 4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]]</code>.');
- text: <code>combinations(4, 6)</code> should return <code>[[0,1,2,3], [0,1,2,4], [0,1,2,5], [0,1,3,4], [0,1,3,5], [0,1,4,5], [0,2,3,4], [0,2,3,5], [0,2,4,5], [0,3,4,5], [1,2,3,4], [1,2,3,5], [1,2,4,5], [1,3,4,5], [2,3,4,5]]</code>
testString: assert.deepEqual(combinations(testInput2[0], testInput2[1]), testOutput2, '<code>combinations(4, 6)</code> should return <code>[[0,1,2,3], [0,1,2,4], [0,1,2,5], [0,1,3,4], [0,1,3,5], [0,1,4,5], [0,2,3,4], [0,2,3,5], [0,2,4,5], [0,3,4,5], [1,2,3,4], [1,2,3,5], [1,2,4,5], [1,3,4,5], [2,3,4,5]]</code>');
```
@ -64,7 +64,11 @@ function combinations (m, n) {
<div id='js-teardown'>
```js
console.info('after the test');
const testInput1 = [3, 5];
const testOutput1 = [[0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 2, 3], [0, 2, 4], [0, 3, 4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4]];
const testInput2 = [4, 6];
const testOutput2 = [[0, 1, 2, 3], [0, 1, 2, 4], [0, 1, 2, 5], [0, 1, 3, 4], [0, 1, 3, 5], [0, 1, 4, 5], [0, 2, 3, 4], [0, 2, 3, 5], [0, 2, 4, 5], [0, 3, 4, 5], [1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 4, 5], [1, 3, 4, 5], [2, 3, 4, 5]];
```
</div>

View File

@ -31,17 +31,17 @@ An input of three or more words, e.g. ["ABC", "DEF", "G", "H"], produces the out
```yml
tests:
- text: <code>quibble</code> is a function.
testString: 'assert(typeof quibble === "function", "<code>quibble</code> is a function.");'
- text: '<code>quibble(["ABC"])</code> should return a string.'
testString: 'assert(typeof quibble(["ABC"]) === "string", "<code>quibble(["ABC"])</code> should return a string.");'
- text: '<code>quibble([])</code> should return "{}".'
testString: 'assert.equal(quibble(testCases[0]), results[0], "<code>quibble([])</code> should return "{}".");'
- text: '<code>quibble(["ABC"])</code> should return "{ABC}".'
testString: 'assert.equal(quibble(testCases[1]), results[1], "<code>quibble(["ABC"])</code> should return "{ABC}".");'
- text: '<code>quibble(["ABC", "DEF"])</code> should return "{ABC and DEF}".'
testString: 'assert.equal(quibble(testCases[2]), results[2], "<code>quibble(["ABC", "DEF"])</code> should return "{ABC and DEF}".");'
- text: '<code>quibble(["ABC", "DEF", "G", "H"])</code> should return "{ABC,DEF,G and H}".'
testString: 'assert.equal(quibble(testCases[3]), results[3], "<code>quibble(["ABC", "DEF", "G", "H"])</code> should return "{ABC,DEF,G and H}".");'
testString: assert(typeof quibble === 'function', '<code>quibble</code> is a function.');
- text: <code>quibble(["ABC"])</code> should return a string.
testString: assert(typeof quibble(["ABC"]) === 'string', '<code>quibble(["ABC"])</code> should return a string.');
- text: <code>quibble([])</code> should return "{}".
testString: assert.equal(quibble(testCases[0]), results[0], '<code>quibble([])</code> should return "{}".');
- text: <code>quibble(["ABC"])</code> should return "{ABC}".
testString: assert.equal(quibble(testCases[1]), results[1], '<code>quibble(["ABC"])</code> should return "{ABC}".');
- text: <code>quibble(["ABC", "DEF"])</code> should return "{ABC and DEF}".
testString: assert.equal(quibble(testCases[2]), results[2], '<code>quibble(["ABC", "DEF"])</code> should return "{ABC and DEF}".');
- text: <code>quibble(["ABC", "DEF", "G", "H"])</code> should return "{ABC,DEF,G and H}".
testString: assert.equal(quibble(testCases[3]), results[3], '<code>quibble(["ABC", "DEF", "G", "H"])</code> should return "{ABC,DEF,G and H}".');
```
@ -66,7 +66,8 @@ function quibble (words) {
<div id='js-teardown'>
```js
console.info('after the test');
const testCases = [[], ["ABC"], ["ABC", "DEF"], ["ABC", "DEF", "G", "H"]];
const results = ["{}", "{ABC}", "{ABC and DEF}", "{ABC,DEF,G and H}"];
```
</div>
@ -82,7 +83,7 @@ function quibble (words) {
return "{" +
words.slice(0, words.length - 1).join(",") +
(words.length > 1 ? " and " : "") +
(words[words.length - 1] || ") +
(words[words.length - 1] || '') +
"}";
}

View File

@ -21,29 +21,29 @@ challengeType: 5
```yml
tests:
- text: <code>allEqual</code> is a function.
testString: 'assert(typeof allEqual === "function", "<code>allEqual</code> is a function.");'
testString: assert(typeof allEqual === 'function', '<code>allEqual</code> is a function.');
- text: <code>azSorted</code> is a function.
testString: 'assert(typeof azSorted === "function", "<code>azSorted</code> is a function.");'
- text: '<code>allEqual(["AA", "AA", "AA", "AA"])</code> returns true.'
testString: 'assert(allEqual(testCases[0]), "<code>allEqual(["AA", "AA", "AA", "AA"])</code> returns true.");'
- text: '<code>azSorted(["AA", "AA", "AA", "AA"])</code> returns false.'
testString: 'assert(!azSorted(testCases[0]), "<code>azSorted(["AA", "AA", "AA", "AA"])</code> returns false.");'
- text: '<code>allEqual(["AA", "ACB", "BB", "CC"])</code> returns false.'
testString: 'assert(!allEqual(testCases[1]), "<code>allEqual(["AA", "ACB", "BB", "CC"])</code> returns false.");'
- text: '<code>azSorted(["AA", "ACB", "BB", "CC"])</code> returns true.'
testString: 'assert(azSorted(testCases[1]), "<code>azSorted(["AA", "ACB", "BB", "CC"])</code> returns true.");'
- text: '<code>allEqual([])</code> returns true.'
testString: 'assert(allEqual(testCases[2]), "<code>allEqual([])</code> returns true.");'
- text: '<code>azSorted([])</code> returns true.'
testString: 'assert(azSorted(testCases[2]), "<code>azSorted([])</code> returns true.");'
- text: '<code>allEqual(["AA"])</code> returns true.'
testString: 'assert(allEqual(testCases[3]), "<code>allEqual(["AA"])</code> returns true.");'
- text: '<code>azSorted(["AA"])</code> returns true.'
testString: 'assert(azSorted(testCases[3]), "<code>azSorted(["AA"])</code> returns true.");'
- text: '<code>allEqual(["BB", "AA"])</code> returns false.'
testString: 'assert(!allEqual(testCases[4]), "<code>allEqual(["BB", "AA"])</code> returns false.");'
- text: '<code>azSorted(["BB", "AA"])</code> returns false.'
testString: 'assert(!azSorted(testCases[4]), "<code>azSorted(["BB", "AA"])</code> returns false.");'
testString: assert(typeof azSorted === 'function', '<code>azSorted</code> is a function.');
- text: <code>allEqual(["AA", "AA", "AA", "AA"])</code> returns true.
testString: assert(allEqual(testCases[0]), '<code>allEqual(["AA", "AA", "AA", "AA"])</code> returns true.');
- text: <code>azSorted(["AA", "AA", "AA", "AA"])</code> returns false.
testString: assert(!azSorted(testCases[0]), '<code>azSorted(["AA", "AA", "AA", "AA"])</code> returns false.');
- text: <code>allEqual(["AA", "ACB", "BB", "CC"])</code> returns false.
testString: assert(!allEqual(testCases[1]), '<code>allEqual(["AA", "ACB", "BB", "CC"])</code> returns false.');
- text: <code>azSorted(["AA", "ACB", "BB", "CC"])</code> returns true.
testString: assert(azSorted(testCases[1]), '<code>azSorted(["AA", "ACB", "BB", "CC"])</code> returns true.');
- text: <code>allEqual([])</code> returns true.
testString: assert(allEqual(testCases[2]), '<code>allEqual([])</code> returns true.');
- text: <code>azSorted([])</code> returns true.
testString: assert(azSorted(testCases[2]), '<code>azSorted([])</code> returns true.');
- text: <code>allEqual(["AA"])</code> returns true.
testString: assert(allEqual(testCases[3]), '<code>allEqual(["AA"])</code> returns true.');
- text: <code>azSorted(["AA"])</code> returns true.
testString: assert(azSorted(testCases[3]), '<code>azSorted(["AA"])</code> returns true.');
- text: <code>allEqual(["BB", "AA"])</code> returns false.
testString: assert(!allEqual(testCases[4]), '<code>allEqual(["BB", "AA"])</code> returns false.');
- text: <code>azSorted(["BB", "AA"])</code> returns false.
testString: assert(!azSorted(testCases[4]), '<code>azSorted(["BB", "AA"])</code> returns false.');
```
@ -73,7 +73,7 @@ function azSorted (arr) {
<div id='js-teardown'>
```js
console.info('after the test');
const testCases = [['AA', 'AA', 'AA', 'AA'], ['AA', 'ACB', 'BB', 'CC'], [], ['AA'], ['BB', 'AA']];
```
</div>

View File

@ -82,13 +82,13 @@ However, only include quantities with non-zero values in the output (e.g., retur
```yml
tests:
- text: <code>convertSeconds</code> is a function.
testString: 'assert(typeof convertSeconds === "function", "<code>convertSeconds</code> is a function.");'
- text: '<code>convertSeconds(7259)</code> should return <code>2 hr, 59 sec</code>.'
testString: 'assert.equal(convertSeconds(testCases[0]), results[0], "<code>convertSeconds(7259)</code> should return <code>2 hr, 59 sec</code>.");'
testString: assert(typeof convertSeconds === 'function', '<code>convertSeconds</code> is a function.');
- text: <code>convertSeconds(7259)</code> should return <code>2 hr, 59 sec</code>.
testString: assert.equal(convertSeconds(testCases[0]), results[0], '<code>convertSeconds(7259)</code> should return <code>2 hr, 59 sec</code>.');
- text: <code>convertSeconds(86400)</code> should return <code>1 d</code>.
testString: 'assert.equal(convertSeconds(testCases[1]), results[1], "<code>convertSeconds(86400)</code> should return <code>1 d</code>.");'
- text: '<code>convertSeconds(6000000)</code> should return <code>9 wk, 6 d, 10 hr, 40 min</code>.'
testString: 'assert.equal(convertSeconds(testCases[2]), results[2], "<code>convertSeconds(6000000)</code> should return <code>9 wk, 6 d, 10 hr, 40 min</code>.");'
testString: assert.equal(convertSeconds(testCases[1]), results[1], '<code>convertSeconds(86400)</code> should return <code>1 d</code>.');
- text: <code>convertSeconds(6000000)</code> should return <code>9 wk, 6 d, 10 hr, 40 min</code>.
testString: assert.equal(convertSeconds(testCases[2]), results[2], '<code>convertSeconds(6000000)</code> should return <code>9 wk, 6 d, 10 hr, 40 min</code>.');
```
@ -113,7 +113,8 @@ function convertSeconds (sec) {
<div id='js-teardown'>
```js
console.info('after the test');
const testCases = [7259, 86400, 6000000];
const results = ['2 hr, 59 sec', '1 d', '9 wk, 6 d, 10 hr, 40 min'];
```
</div>

View File

@ -25,13 +25,13 @@ the second a substring to be searched for.
```yml
tests:
- text: <code>countSubstring</code> is a function.
testString: 'assert(typeof countSubstring === "function", "<code>countSubstring</code> is a function.");'
- text: '<code>countSubstring("the three truths", "th")</code> should return <code>3</code>.'
testString: 'assert.equal(countSubstring(testCases[0], searchString[0]), results[0], "<code>countSubstring("the three truths", "th")</code> should return <code>3</code>.");'
- text: '<code>countSubstring("ababababab", "abab")</code> should return <code>2</code>.'
testString: 'assert.equal(countSubstring(testCases[1], searchString[1]), results[1], "<code>countSubstring("ababababab", "abab")</code> should return <code>2</code>.");'
- text: '<code>countSubstring("abaabba*bbaba*bbab", "a*b")</code> should return <code>2</code>.'
testString: 'assert.equal(countSubstring(testCases[2], searchString[2]), results[2], "<code>countSubstring("abaabba*bbaba*bbab", "a*b")</code> should return <code>2</code>.");'
testString: assert(typeof countSubstring === 'function', '<code>countSubstring</code> is a function.');
- text: <code>countSubstring("the three truths", "th")</code> should return <code>3</code>.
testString: assert.equal(countSubstring(testCases[0], searchString[0]), results[0], '<code>countSubstring("the three truths", "th")</code> should return <code>3</code>.');
- text: <code>countSubstring("ababababab", "abab")</code> should return <code>2</code>.
testString: assert.equal(countSubstring(testCases[1], searchString[1]), results[1], '<code>countSubstring("ababababab", "abab")</code> should return <code>2</code>.');
- text: <code>countSubstring("abaabba*bbaba*bbab", "a*b")</code> should return <code>2</code>.
testString: assert.equal(countSubstring(testCases[2], searchString[2]), results[2], '<code>countSubstring("abaabba*bbaba*bbab", "a*b")</code> should return <code>2</code>.');
```
@ -56,7 +56,9 @@ function countSubstring (str, subStr) {
<div id='js-teardown'>
```js
console.info('after the test');
const testCases = ['the three truths', 'ababababab', 'abaabba*bbaba*bbab'];
const searchString = ['th', 'abab', 'a*b'];
const results = [3, 2, 2];
```
</div>

View File

@ -35,9 +35,9 @@ Reference:
```yml
tests:
- text: <code>countCoins</code> is a function.
testString: 'assert(typeof countCoins === "function", "<code>countCoins</code> is a function.");'
testString: assert(typeof countCoins === 'function', '<code>countCoins</code> is a function.');
- text: <code>countCoints()</code> should return 242.
testString: 'assert.equal(countCoins(), 242, "<code>countCoints()</code> should return 242.");'
testString: assert.equal(countCoins(), 242, '<code>countCoints()</code> should return 242.');
```

View File

@ -38,11 +38,11 @@ w+3x+3y-z=-47 \\
```yml
tests:
- text: <code>cramersRule</code> is a function.
testString: 'assert(typeof cramersRule === "function", "<code>cramersRule</code> is a function.");'
- text: '<code>cramersRule([[2, -1, 5, 1], [3, 2, 2, -6], [1, 3, 3, -1], [5, -2, -3, 3]], [-3, -32, -47, 49])</code> should return <code>[2, -12, -4, 1]</code>.'
testString: 'assert.deepEqual(cramersRule(matrices[0], freeTerms[0]), answers[0], "<code>cramersRule([[2, -1, 5, 1], [3, 2, 2, -6], [1, 3, 3, -1], [5, -2, -3, 3]], [-3, -32, -47, 49])</code> should return <code>[2, -12, -4, 1]</code>.");'
- text: '<code>cramersRule([[3, 1, 1], [2, 2, 5], [1, -3, -4]], [3, -1, 2])</code> should return <code>[1, 1, -1]</code>.'
testString: 'assert.deepEqual(cramersRule(matrices[1], freeTerms[1]), answers[1], "<code>cramersRule([[3, 1, 1], [2, 2, 5], [1, -3, -4]], [3, -1, 2])</code> should return <code>[1, 1, -1]</code>.");'
testString: assert(typeof cramersRule === 'function', '<code>cramersRule</code> is a function.');
- text: <code>cramersRule([[2, -1, 5, 1], [3, 2, 2, -6], [1, 3, 3, -1], [5, -2, -3, 3]], [-3, -32, -47, 49])</code> should return <code>[2, -12, -4, 1]</code>.
testString: assert.deepEqual(cramersRule(matrices[0], freeTerms[0]), answers[0], '<code>cramersRule([[2, -1, 5, 1], [3, 2, 2, -6], [1, 3, 3, -1], [5, -2, -3, 3]], [-3, -32, -47, 49])</code> should return <code>[2, -12, -4, 1]</code>.');
- text: <code>cramersRule([[3, 1, 1], [2, 2, 5], [1, -3, -4]], [3, -1, 2])</code> should return <code>[1, 1, -1]</code>.
testString: assert.deepEqual(cramersRule(matrices[1], freeTerms[1]), answers[1], '<code>cramersRule([[3, 1, 1], [2, 2, 5], [1, -3, -4]], [3, -1, 2])</code> should return <code>[1, 1, -1]</code>.');
```
@ -67,7 +67,22 @@ function cramersRule (matrix, freeTerms) {
<div id='js-teardown'>
```js
console.info('after the test');
const matrices = [
[
[2, -1, 5, 1],
[3, 2, 2, -6],
[1, 3, 3, -1],
[5, -2, -3, 3]
],
[
[3, 1, 1],
[2, 2, 5],
[1, -3, -4]
]
];
const freeTerms = [[-3, -32, -47, 49], [3, -1, 2]];
const answers = [[2, -12, -4, 1], [1, 1, -1]];
```
</div>

View File

@ -24,13 +24,13 @@ Task:
```yml
tests:
- text: <code>getDateFormats</code> is a function.
testString: 'assert(typeof getDateFormats === "function", "<code>getDateFormats</code> is a function.");'
testString: assert(typeof getDateFormats === 'function', '<code>getDateFormats</code> is a function.');
- text: Should return an object.
testString: 'assert(typeof getDateFormats() === "object", "Should return an object.");'
testString: assert(typeof getDateFormats() === 'object', 'Should return an object.');
- text: Should returned an array with 2 elements.
testString: 'assert(getDateFormats().length === 2, "Should returned an array with 2 elements.");'
testString: assert(getDateFormats().length === 2, 'Should returned an array with 2 elements.');
- text: Should return the correct date in the right format
testString: 'assert.deepEqual(getDateFormats(), dates, equalsMessage);'
testString: assert.deepEqual(getDateFormats(), dates, equalsMessage);
```
@ -55,7 +55,17 @@ function getDateFormats () {
<div id='js-teardown'>
```js
console.info('after the test');
const getDateSolution = () => {
const date = new Date();
const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
const fmt1 = `${date.getFullYear()}-${(1 + date.getMonth())}-${date.getDate()}`;
const fmt2 = `${weekdays[date.getDay()]}, ${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
return [fmt1, fmt2];
};
const dates = getDateSolution();
const equalsMessage = `message: <code>getDataFormats()</code> should return <code>["${dates[0]}", "${dates[1]}"]</code>.`;
```
</div>

View File

@ -26,19 +26,19 @@ Task:
```yml
tests:
- text: <code>add12Hours</code> is a function.
testString: 'assert(typeof add12Hours === "function", "<code>add12Hours</code> is a function.");'
testString: assert(typeof add12Hours === 'function', '<code>add12Hours</code> is a function.');
- text: <code>add12Hours(dateString)</code> should return a string.
testString: 'assert(typeof add12Hours(tests[0]) === "string", "<code>add12Hours(dateString)</code> should return a string.");'
- text: '<code>add12Hours("" + tests[0] + "")</code> should return <code>"" + answers[0] + ""</code>'
testString: 'assert(add12Hours(tests[0]) === answers[0], "<code>add12Hours("" + tests[0] + "")</code> should return <code>"" + answers[0] + ""</code>");'
- text: 'Should handel day change. <code>add12Hours("" + tests[1] + "")</code> should return <code>"" + answers[1] + ""</code>'
testString: 'assert(add12Hours(tests[1]) === answers[1], "Should handel day change. <code>add12Hours("" + tests[1] + "")</code> should return <code>"" + answers[1] + ""</code>");'
- text: 'Should handel month change in a leap years. <code>add12Hours("" + tests[2] + "")</code> should return <code>"" + answers[2] + ""</code>'
testString: 'assert(add12Hours(tests[2]) === answers[2], "Should handel month change in a leap years. <code>add12Hours("" + tests[2] + "")</code> should return <code>"" + answers[2] + ""</code>");'
- text: 'Should handel month change in a common years. <code>add12Hours("" + tests[3] + "")</code> should return <code>"" + answers[3] + ""</code>'
testString: 'assert(add12Hours(tests[3]) === answers[3], "Should handel month change in a common years. <code>add12Hours("" + tests[3] + "")</code> should return <code>"" + answers[3] + ""</code>");'
- text: 'Should handel year change. <code>add12Hours("" + tests[4] + "")</code> should return <code>"" + answers[4] + ""</code>'
testString: 'assert(add12Hours(tests[4]) === answers[4], "Should handel year change. <code>add12Hours("" + tests[4] + "")</code> should return <code>"" + answers[4] + ""</code>");'
testString: assert(typeof add12Hours('January 17 2017 11:43am EST') === 'string', '<code>add12Hours(dateString)</code> should return a string.');
- text: <code>add12Hours("January 17 2017 11:43am EST")</code> should return <code>"January 17 2017 11:43pm EST"</code>
testString: assert(add12Hours('January 17 2017 11:43am EST') === 'January 17 2017 11:43pm EST', '<code>add12Hours("January 17 2017 11:43am EST")</code> should return <code>"January 17 2017 11:43pm EST"</code>');
- text: Should handel day change. <code>add12Hours("March 7 2009 7:30pm EST")</code> should return <code>"March 8 2009 7:30am EST"</code>
testString: assert(add12Hours('March 7 2009 7:30pm EST') === 'March 8 2009 7:30am EST', 'Should handel day change. <code>add12Hours("March 7 2009 7:30pm EST")</code> should return <code>"March 8 2009 7:30am EST"</code>');
- text: Should handel month change in a leap years. <code>add12Hours("February 29 2004 9:15pm EST")</code> should return <code>"March 1 2004 9:15am EST"</code>
testString: assert(add12Hours('February 29 2004 9:15pm EST') === 'March 1 2004 9:15am EST', 'Should handel month change in a leap years. <code>add12Hours("February 29 2004 9:15pm EST")</code> should return <code>"March 1 2004 9:15am EST"</code>');
- text: Should handel month change in a common years. <code>add12Hours("February 28 1999 3:15pm EST")</code> should return <code>"March 1 1999 3:15am EST"</code>
testString: assert(add12Hours('February 28 1999 3:15pm EST') === 'March 1 1999 3:15am EST', 'Should handel month change in a common years. <code>add12Hours("February 28 1999 3:15pm EST")</code> should return <code>"March 1 1999 3:15am EST"</code>');
- text: Should handel year change. <code>add12Hours("December 31 2020 1:45pm EST")</code> should return <code>"January 1 2021 1:45am EST"</code>
testString: assert(add12Hours('December 31 2020 1:45pm EST') === 'January 1 2021 1:45am EST', 'Should handel year change. <code>add12Hours("December 31 2020 1:45pm EST")</code> should return <code>"January 1 2021 1:45am EST"</code>');
```
@ -58,16 +58,6 @@ function add12Hours (dateString) {
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution

View File

@ -22,13 +22,13 @@ challengeType: 5
```yml
tests:
- text: <code>findXmasSunday</code> is a function.
testString: 'assert(typeof findXmasSunday === "function", "<code>findXmasSunday</code> is a function.");'
- text: '<code>findChristmasSunday(2000, 2100)</code> should return an array.'
testString: 'assert(typeof findXmasSunday(2000, 2100) === "object", "<code>findChristmasSunday(2000, 2100)</code> should return an array.");'
- text: '<code>findChristmasSunday(2008, 2121</code> should return [1977, 1983, 1988, 1994, 2005, 2011, 2016]'
testString: 'assert.deepEqual(findXmasSunday(1970, 2017), firstSolution, "<code>findChristmasSunday(2008, 2121</code> should return [1977, 1983, 1988, 1994, 2005, 2011, 2016]");'
- text: '<code>findChristmasSunday(2008, 2121</code> should return [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]'
testString: 'assert.deepEqual(findXmasSunday(2008, 2121), secondSolution, "<code>findChristmasSunday(2008, 2121</code> should return [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]");'
testString: assert(typeof findXmasSunday === 'function', '<code>findXmasSunday</code> is a function.');
- text: <code>findChristmasSunday(2000, 2100)</code> should return an array.
testString: assert(typeof findXmasSunday(2000, 2100) === 'object', '<code>findChristmasSunday(2000, 2100)</code> should return an array.');
- text: <code>findChristmasSunday(2008, 2121</code> should return [1977, 1983, 1988, 1994, 2005, 2011, 2016]
testString: assert.deepEqual(findXmasSunday(1970, 2017), firstSolution, '<code>findChristmasSunday(2008, 2121</code> should return [1977, 1983, 1988, 1994, 2005, 2011, 2016]');
- text: <code>findChristmasSunday(2008, 2121</code> should return [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]
testString: assert.deepEqual(findXmasSunday(2008, 2121), secondSolution, '<code>findChristmasSunday(2008, 2121</code> should return [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118]');
```
@ -53,7 +53,8 @@ function findXmasSunday (start, end) {
<div id='js-teardown'>
```js
console.info('after the test');
const firstSolution = [1977, 1983, 1988, 1994, 2005, 2011, 2016];
const secondSolution = [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118];
```
</div>

View File

@ -67,15 +67,15 @@ Task:
```yml
tests:
- text: <code>dealFreeCell</code> is a function.
testString: 'assert(typeof dealFreeCell === "function", "<code>dealFreeCell</code> is a function.");'
testString: assert(typeof dealFreeCell === 'function', '<code>dealFreeCell</code> is a function.');
- text: <code>dealFreeCell(seed)</code> should return an object.
testString: 'assert(typeof dealFreeCell(1) === "object", "<code>dealFreeCell(seed)</code> should return an object.");'
testString: assert(typeof dealFreeCell(1) === 'object', '<code>dealFreeCell(seed)</code> should return an object.');
- text: <code>dealFreeCell(seed)</code> should return an array of length 7.
testString: 'assert(dealFreeCell(1).length === 7, "<code>dealFreeCell(seed)</code> should return an array of length 7.");'
- text: '<code>dealFreeCell(1)</code> should return an array identical to example "Game #1"'
testString: 'assert.deepEqual(dealFreeCell(1), game1, "<code>dealFreeCell(1)</code> should return an array identical to example "Game #1"");'
- text: '<code>dealFreeCell(617)</code> should return an array identical to example "Game #617"'
testString: 'assert.deepEqual(dealFreeCell(617), game617, "<code>dealFreeCell(617)</code> should return an array identical to example "Game #617"");'
testString: assert(dealFreeCell(1).length === 7, '<code>dealFreeCell(seed)</code> should return an array of length 7.');
- text: "<code>dealFreeCell(1)</code> should return an array identical to example \"Game #1\""
testString: "assert.deepEqual(dealFreeCell(1), game1, '<code>dealFreeCell(1)</code> should return an array identical to example \"Game #1\"');"
- text: "<code>dealFreeCell(617)</code> should return an array identical to example \"Game #617\""
testString: "assert.deepEqual(dealFreeCell(617), game617, '<code>dealFreeCell(617)</code> should return an array identical to example \"Game #617\"');"
```
@ -100,7 +100,25 @@ function dealFreeCell (seed) {
<div id='js-teardown'>
```js
console.info('after the test');
const replaceThis = 3;
const game1 = [
['JD', '2D', '9H', 'JC', '5D', '7H', '7C', '5H'],
['KD', 'KC', '9S', '5S', 'AD', 'QC', 'KH', '3H'],
['2S', 'KS', '9D', 'QD', 'JS', 'AS', 'AH', '3C'],
['4C', '5C', 'TS', 'QH', '4H', 'AC', '4D', '7S'],
['3S', 'TD', '4S', 'TH', '8H', '2C', 'JH', '7D'],
['6D', '8S', '8D', 'QS', '6C', '3D', '8C', 'TC'],
['6S', '9C', '2H', '6H']
];
const game617 = [
['7D', 'AD', '5C', '3S', '5S', '8C', '2D', 'AH'],
['TD', '7S', 'QD', 'AC', '6D', '8H', 'AS', 'KH'],
['TH', 'QC', '3H', '9D', '6S', '8D', '3D', 'TC'],
['KD', '5H', '9S', '3C', '8S', '7H', '4D', 'JS'],
['4C', 'QS', '9C', '9H', '7C', '6H', '2C', '2S'],
['4S', 'TS', '2H', '5D', 'JC', '6C', 'JH', 'QH'],
['JD', 'KS', 'KC', '4H']
];
```
</div>

View File

@ -27,15 +27,15 @@ Prototype copying
```yml
tests:
- text: <code>deepcopy</code> should be a function.
testString: 'assert(typeof deepcopy === "function", "<code>deepcopy</code> should be a function.");'
testString: assert(typeof deepcopy === 'function', '<code>deepcopy</code> should be a function.');
- text: '<code>deepcopy({test: "test"})</code> should return an object.'
testString: 'assert(typeof deepcopy(obj1) === "object", "<code>deepcopy({test: "test"})</code> should return an object.");'
testString: 'assert(typeof deepcopy(obj1) === ''object'', ''<code>deepcopy({test: "test"})</code> should return an object.'');'
- text: Should not return the same object that was provided.
testString: 'assert(deepcopy(obj2) != obj2, "Should not return the same object that was provided.");'
- text: 'When passed an object containing an array, should return a deep copy of the object.'
testString: 'assert.deepEqual(deepcopy(obj2), obj2, "When passed an object containing an array, should return a deep copy of the object.");'
- text: 'When passed an object containing another object, should return a deep copy of the object.'
testString: 'assert.deepEqual(deepcopy(obj3), obj3, "When passed an object containing another object, should return a deep copy of the object.");'
testString: assert(deepcopy(obj2) != obj2, 'Should not return the same object that was provided.');
- text: When passed an object containing an array, should return a deep copy of the object.
testString: assert.deepEqual(deepcopy(obj2), obj2, 'When passed an object containing an array, should return a deep copy of the object.');
- text: When passed an object containing another object, should return a deep copy of the object.
testString: assert.deepEqual(deepcopy(obj3), obj3, 'When passed an object containing another object, should return a deep copy of the object.');
```
@ -60,7 +60,15 @@ function deepcopy (obj) {
<div id='js-teardown'>
```js
console.info('after the test');
const obj1 = { test: 'test' };
const obj2 = {
t: 'test',
a: ['an', 'array']
};
const obj3 = {
t: 'try',
o: obj2
};
```
</div>

View File

@ -26,33 +26,33 @@ it should throw a <code>TypeError</code> with an error message of <code>'Not a N
```yml
tests:
- text: <code>Num</code> should be a function.
testString: 'assert(typeof Num === "function", "<code>Num</code> should be a function.");'
testString: assert(typeof Num === 'function', '<code>Num</code> should be a function.');
- text: <code>new Num(4)</code> should return an object.
testString: 'assert(typeof (new Num(4)) === "object", "<code>new Num(4)</code> should return an object.");'
testString: assert(typeof (new Num(4)) === 'object', '<code>new Num(4)</code> should return an object.');
- text: <code>new Num(\'test\')</code> should throw a TypeError with message \'Not a Number\'.
testString: 'assert(throws(() => new Num("test"), TypeError, "Not a Number"), "<code>new Num(\"test\")</code> should throw a TypeError with message \"Not a Number\".");'
testString: assert(throws(() => new Num('test'), TypeError, 'Not a Number'), '<code>new Num(\'test\')</code> should throw a TypeError with message \'Not a Number\'.');
- text: <code>new Num(0)</code> should throw a TypeError with message \'Out of range\'.
testString: 'assert(throws(() => new Num(0), TypeError, "Out of range"), "<code>new Num(0)</code> should throw a TypeError with message \"Out of range\".");'
testString: assert(throws(() => new Num(0), TypeError, 'Out of range'), '<code>new Num(0)</code> should throw a TypeError with message \'Out of range\'.');
- text: <code>new Num(-5)</code> should throw a TypeError with message \'Out of range\'.
testString: 'assert(throws(() => new Num(-5), TypeError, "Out of range"), "<code>new Num(-5)</code> should throw a TypeError with message \"Out of range\".");'
testString: assert(throws(() => new Num(-5), TypeError, 'Out of range'), '<code>new Num(-5)</code> should throw a TypeError with message \'Out of range\'.');
- text: <code>new Num(10)</code> should throw a TypeError with message \'Out of range\'.
testString: 'assert(throws(() => new Num(11), TypeError, "Out of range"), "<code>new Num(10)</code> should throw a TypeError with message \"Out of range\".");'
testString: assert(throws(() => new Num(11), TypeError, 'Out of range'), '<code>new Num(10)</code> should throw a TypeError with message \'Out of range\'.');
- text: <code>new Num(20)</code> should throw a TypeError with message \'Out of range\'.
testString: 'assert(throws(() => new Num(20), TypeError, "Out of range"), "<code>new Num(20)</code> should throw a TypeError with message \"Out of range\".");'
testString: assert(throws(() => new Num(20), TypeError, 'Out of range'), '<code>new Num(20)</code> should throw a TypeError with message \'Out of range\'.');
- text: <code>new Num(3) + new Num(4)</code> should equal 7.
testString: 'assert.equal(new Num(3) + new Num(4), 7, "<code>new Num(3) + new Num(4)</code> should equal 7.");'
testString: assert.equal(new Num(3) + new Num(4), 7, '<code>new Num(3) + new Num(4)</code> should equal 7.');
- text: <code>new Num(3) - new Num(4)</code> should equal -1.
testString: 'assert.equal(new Num(3) - new Num(4), -1, "<code>new Num(3) - new Num(4)</code> should equal -1.");'
testString: assert.equal(new Num(3) - new Num(4), -1, '<code>new Num(3) - new Num(4)</code> should equal -1.');
- text: <code>new Num(3) * new Num(4)</code> should equal 12.
testString: 'assert.equal(new Num(3) * new Num(4), 12, "<code>new Num(3) * new Num(4)</code> should equal 12.");'
testString: assert.equal(new Num(3) * new Num(4), 12, '<code>new Num(3) * new Num(4)</code> should equal 12.');
- text: <code>new Num(3) / new Num(4)</code> should equal 0.75.
testString: 'assert.equal(new Num(3) / new Num(4), 0.75, "<code>new Num(3) / new Num(4)</code> should equal 0.75.");'
testString: assert.equal(new Num(3) / new Num(4), 0.75, '<code>new Num(3) / new Num(4)</code> should equal 0.75.');
- text: <code>new Num(3) < new Num(4)</code> should be true.
testString: 'assert(new Num(3) < new Num(4), "<code>new Num(3) < new Num(4)</code> should be true.");'
testString: assert(new Num(3) < new Num(4), '<code>new Num(3) < new Num(4)</code> should be true.');
- text: <code>new Num(3) > new Num(4)</code> should be false.
testString: 'assert(!(new Num(3) > new Num(4)), "<code>new Num(3) > new Num(4)</code> should be false.");'
testString: assert(!(new Num(3) > new Num(4)), '<code>new Num(3) > new Num(4)</code> should be false.');
- text: <code>(new Num(5)).toString()</code> should return \'5\'
testString: 'assert.equal((new Num(5)).toString(), "5", "<code>(new Num(5)).toString()</code> should return \"5\"");'
testString: assert.equal((new Num(5)).toString(), '5', '<code>(new Num(5)).toString()</code> should return \'5\'');
```
@ -97,7 +97,7 @@ Num.prototype.toString = function () { return this._value.toString(); };
function throws(func, errorType, msg) {
let hasThrown = false;
let errorMsg = ";
let errorMsg = '';
let correctType = false;
try {
func();

View File

@ -40,13 +40,13 @@ Task:
```yml
tests:
- text: <code>combinations</code> should be a function.
testString: 'assert(typeof combinations === "function", "<code>combinations</code> should be a function.");'
- text: '<code>combinations([1, 2, 3], 6)</code> should return an Array.'
testString: 'assert(Array.isArray(combinations([1, 2, 3], 6)), "<code>combinations([1, 2, 3], 6)</code> should return an Array.");'
- text: '<code>combinations([1, 2, 3, 4, 5, 6, 7], 12)</code> should return an array of length 14.'
testString: 'assert(combinations(nums, total).length === len, "<code>combinations([1, 2, 3, 4, 5, 6, 7], 12)</code> should return an array of length 14.");'
- text: '<code>combinations([1, 2, 3, 4, 5, 6, 7], 12)</code> should return all valid combinations.'
testString: 'assert.deepEqual(combinations(nums, total), result, "<code>combinations([1, 2, 3, 4, 5, 6, 7], 12)</code> should return all valid combinations.");'
testString: assert(typeof combinations === 'function', '<code>combinations</code> should be a function.');
- text: <code>combinations([1, 2, 3], 6)</code> should return an Array.
testString: assert(Array.isArray(combinations([1, 2, 3], 6)), '<code>combinations([1, 2, 3], 6)</code> should return an Array.');
- text: <code>combinations([1, 2, 3, 4, 5, 6, 7], 12)</code> should return an array of length 14.
testString: assert(combinations(nums, total).length === len, '<code>combinations([1, 2, 3, 4, 5, 6, 7], 12)</code> should return an array of length 14.');
- text: <code>combinations([1, 2, 3, 4, 5, 6, 7], 12)</code> should return all valid combinations.
testString: assert.deepEqual(combinations(nums, total), result, '<code>combinations([1, 2, 3, 4, 5, 6, 7], 12)</code> should return all valid combinations.');
```
@ -71,7 +71,25 @@ function combinations (possibleNumbers, total) {
<div id='js-teardown'>
```js
console.info('after the test');
const nums = [1, 2, 3, 4, 5, 6, 7];
const total = 12;
const len = 14;
const result = [
[2, 3, 7],
[2, 4, 6],
[2, 6, 4],
[2, 7, 3],
[4, 1, 7],
[4, 2, 6],
[4, 3, 5],
[4, 5, 3],
[4, 6, 2],
[4, 7, 1],
[6, 1, 5],
[6, 2, 4],
[6, 4, 2],
[6, 5, 1]
];
```
</div>

View File

@ -21,21 +21,21 @@ Task:
```yml
tests:
- text: <code>discordianDate</code> is a function.
testString: 'assert(typeof discordianDate === "function", "<code>discordianDate</code> is a function.");'
- text: '<code>discordianDate(new Date(2010, 6, 22))</code> should return <code>"Pungenday, the 57th day of Confusion in the YOLD 3176"</code>.'
testString: 'assert(discordianDate(new Date(2010, 6, 22)) === "Pungenday, the 57th day of Confusion in the YOLD 3176", "<code>discordianDate(new Date(2010, 6, 22))</code> should return <code>"Pungenday, the 57th day of Confusion in the YOLD 3176"</code>.");'
- text: '<code>discordianDate(new Date(2012, 1, 28))</code> should return <code>"Prickle-Prickle, the 59th day of Chaos in the YOLD 3178"</code>.'
testString: 'assert(discordianDate(new Date(2012, 1, 28)) === "Prickle-Prickle, the 59th day of Chaos in the YOLD 3178", "<code>discordianDate(new Date(2012, 1, 28))</code> should return <code>"Prickle-Prickle, the 59th day of Chaos in the YOLD 3178"</code>.");'
- text: '<code>discordianDate(new Date(2012, 1, 29))</code> should return <code>"Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib\"s Day!"</code>.'
testString: 'assert(discordianDate(new Date(2012, 1, 29)) === "Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib\"s Day!", "<code>discordianDate(new Date(2012, 1, 29))</code> should return <code>"Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib\"s Day!"</code>.");'
- text: '<code>discordianDate(new Date(2012, 2, 1))</code> should return <code>"Setting Orange, the 60th day of Chaos in the YOLD 3178"</code>.'
testString: 'assert(discordianDate(new Date(2012, 2, 1)) === "Setting Orange, the 60th day of Chaos in the YOLD 3178", "<code>discordianDate(new Date(2012, 2, 1))</code> should return <code>"Setting Orange, the 60th day of Chaos in the YOLD 3178"</code>.");'
- text: '<code>discordianDate(new Date(2010, 0, 5))</code> should return <code>"Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!"</code>.'
testString: 'assert(discordianDate(new Date(2010, 0, 5)) === "Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!", "<code>discordianDate(new Date(2010, 0, 5))</code> should return <code>"Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!"</code>.");'
- text: '<code>discordianDate(new Date(2011, 4, 3))</code> should return <code>"Pungenday, the 50th day of Discord in the YOLD 3177. Celebrate Discoflux!"</code>.'
testString: 'assert(discordianDate(new Date(2011, 4, 3)) === "Pungenday, the 50th day of Discord in the YOLD 3177. Celebrate Discoflux!", "<code>discordianDate(new Date(2011, 4, 3))</code> should return <code>"Pungenday, the 50th day of Discord in the YOLD 3177. Celebrate Discoflux!"</code>.");'
- text: '<code>discordianDate(new Date(2015, 9, 19))</code> should return <code>"Boomtime, the 73rd day of Bureaucracy in the YOLD 3181"</code>.'
testString: 'assert(discordianDate(new Date(2015, 9, 19)) === "Boomtime, the 73rd day of Bureaucracy in the YOLD 3181", "<code>discordianDate(new Date(2015, 9, 19))</code> should return <code>"Boomtime, the 73rd day of Bureaucracy in the YOLD 3181"</code>.");'
testString: assert(typeof discordianDate === 'function', '<code>discordianDate</code> is a function.');
- text: <code>discordianDate(new Date(2010, 6, 22))</code> should return <code>"Pungenday, the 57th day of Confusion in the YOLD 3176"</code>.
testString: assert(discordianDate(new Date(2010, 6, 22)) === 'Pungenday, the 57th day of Confusion in the YOLD 3176', '<code>discordianDate(new Date(2010, 6, 22))</code> should return <code>"Pungenday, the 57th day of Confusion in the YOLD 3176"</code>.');
- text: <code>discordianDate(new Date(2012, 1, 28))</code> should return <code>"Prickle-Prickle, the 59th day of Chaos in the YOLD 3178"</code>.
testString: assert(discordianDate(new Date(2012, 1, 28)) === 'Prickle-Prickle, the 59th day of Chaos in the YOLD 3178', '<code>discordianDate(new Date(2012, 1, 28))</code> should return <code>"Prickle-Prickle, the 59th day of Chaos in the YOLD 3178"</code>.');
- text: <code>discordianDate(new Date(2012, 1, 29))</code> should return <code>"Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib\'s Day!"</code>.
testString: assert(discordianDate(new Date(2012, 1, 29)) === 'Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib\'s Day!', '<code>discordianDate(new Date(2012, 1, 29))</code> should return <code>"Setting Orange, the 60th day of Chaos in the YOLD 3178. Celebrate St. Tib\'s Day!"</code>.');
- text: <code>discordianDate(new Date(2012, 2, 1))</code> should return <code>"Setting Orange, the 60th day of Chaos in the YOLD 3178"</code>.
testString: assert(discordianDate(new Date(2012, 2, 1)) === 'Setting Orange, the 60th day of Chaos in the YOLD 3178', '<code>discordianDate(new Date(2012, 2, 1))</code> should return <code>"Setting Orange, the 60th day of Chaos in the YOLD 3178"</code>.');
- text: <code>discordianDate(new Date(2010, 0, 5))</code> should return <code>"Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!"</code>.
testString: assert(discordianDate(new Date(2010, 0, 5)) === 'Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!', '<code>discordianDate(new Date(2010, 0, 5))</code> should return <code>"Setting Orange, the 5th day of Chaos in the YOLD 3176. Celebrate Mungday!"</code>.');
- text: <code>discordianDate(new Date(2011, 4, 3))</code> should return <code>"Pungenday, the 50th day of Discord in the YOLD 3177. Celebrate Discoflux!"</code>.
testString: assert(discordianDate(new Date(2011, 4, 3)) === 'Pungenday, the 50th day of Discord in the YOLD 3177. Celebrate Discoflux!', '<code>discordianDate(new Date(2011, 4, 3))</code> should return <code>"Pungenday, the 50th day of Discord in the YOLD 3177. Celebrate Discoflux!"</code>.');
- text: <code>discordianDate(new Date(2015, 9, 19))</code> should return <code>"Boomtime, the 73rd day of Bureaucracy in the YOLD 3181"</code>.
testString: assert(discordianDate(new Date(2015, 9, 19)) === 'Boomtime, the 73rd day of Bureaucracy in the YOLD 3181', '<code>discordianDate(new Date(2015, 9, 19))</code> should return <code>"Boomtime, the 73rd day of Bureaucracy in the YOLD 3181"</code>.');
```
@ -153,12 +153,12 @@ function discordianDate(date) {
: (seasonDay % 10 === 3) ? 'rd'
: 'th';
return "
return ''
+ dayOfWeek
+ ', the ' + seasonDay + nth
+ ' day of ' + season
+ ' in the YOLD ' + yold
+ (celebrateHoliday ? '. Celebrate ' + celebrateHoliday + '!' : ")
+ (celebrateHoliday ? '. Celebrate ' + celebrateHoliday + '!' : '')
;
}

View File

@ -26,21 +26,21 @@ challengeType: 5
```yml
tests:
- text: <code>operation</code> is a function.
testString: 'assert(typeof operation === "function", "<code>operation</code> is a function.");'
- text: '<code>operation("m_add",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[2,4],[6,8]]</code>.'
testString: 'assert.deepEqual(operation("m_add", [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[2, 4], [6, 8]], "<code>operation("m_add",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[2,4],[6,8]]</code>.");'
- text: '<code>operation("s_add",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[3,4],[5,6]]</code>.'
testString: 'assert.deepEqual(operation("s_add", [[1, 2], [3, 4]], 2), [[3, 4], [5, 6]], "<code>operation("s_add",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[3,4],[5,6]]</code>.");'
- text: '<code>operation("m_sub",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[0,0],[0,0]]</code>.'
testString: 'assert.deepEqual(operation("m_sub", [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[0, 0], [0, 0]], "<code>operation("m_sub",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[0,0],[0,0]]</code>.");'
- text: '<code>operation("m_mult",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,4],[9,16]]</code>.'
testString: 'assert.deepEqual(operation("m_mult", [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 4], [9, 16]], "<code>operation("m_mult",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,4],[9,16]]</code>.");'
- text: '<code>operation("m_div",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,1],[1,1]]</code>.'
testString: 'assert.deepEqual(operation("m_div", [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 1], [1, 1]], "<code>operation("m_div",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,1],[1,1]]</code>.");'
- text: '<code>operation("m_exp",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,4],[27,256]]</code>.'
testString: 'assert.deepEqual(operation("m_exp", [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 4], [27, 256]], "<code>operation("m_exp",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,4],[27,256]]</code>.");'
- text: '<code>operation("m_add",[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]])</code> should return <code>[[10,12,14,16],[18,20,22,24]]</code>.'
testString: 'assert.deepEqual(operation("m_add", [[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]), [[10, 12, 14, 16], [18, 20, 22, 24]], "<code>operation("m_add",[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]])</code> should return <code>[[10,12,14,16],[18,20,22,24]]</code>.");'
testString: assert(typeof operation === 'function', '<code>operation</code> is a function.');
- text: <code>operation("m_add",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[2,4],[6,8]]</code>.
testString: assert.deepEqual(operation('m_add', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[2, 4], [6, 8]], '<code>operation("m_add",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[2,4],[6,8]]</code>.');
- text: <code>operation("s_add",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[3,4],[5,6]]</code>.
testString: assert.deepEqual(operation('s_add', [[1, 2], [3, 4]], 2), [[3, 4], [5, 6]], '<code>operation("s_add",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[3,4],[5,6]]</code>.');
- text: <code>operation("m_sub",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[0,0],[0,0]]</code>.
testString: assert.deepEqual(operation('m_sub', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[0, 0], [0, 0]], '<code>operation("m_sub",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[0,0],[0,0]]</code>.');
- text: <code>operation("m_mult",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,4],[9,16]]</code>.
testString: assert.deepEqual(operation('m_mult', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 4], [9, 16]], '<code>operation("m_mult",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,4],[9,16]]</code>.');
- text: <code>operation("m_div",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,1],[1,1]]</code>.
testString: assert.deepEqual(operation('m_div', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 1], [1, 1]], '<code>operation("m_div",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,1],[1,1]]</code>.');
- text: <code>operation("m_exp",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,4],[27,256]]</code>.
testString: assert.deepEqual(operation('m_exp', [[1, 2], [3, 4]], [[1, 2], [3, 4]]), [[1, 4], [27, 256]], '<code>operation("m_exp",[[1,2],[3,4]],[[1,2],[3,4]])</code> should return <code>[[1,4],[27,256]]</code>.');
- text: <code>operation("m_add",[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]])</code> should return <code>[[10,12,14,16],[18,20,22,24]]</code>.
testString: assert.deepEqual(operation('m_add', [[1, 2, 3, 4], [5, 6, 7, 8]], [[9, 10, 11, 12], [13, 14, 15, 16]]), [[10, 12, 14, 16], [18, 20, 22, 24]], '<code>operation("m_add",[[1,2,3,4],[5,6,7,8]],[[9,10,11,12],[13,14,15,16]])</code> should return <code>[[10,12,14,16],[18,20,22,24]]</code>.');
```

View File

@ -21,15 +21,15 @@ challengeType: 5
```yml
tests:
- text: <code>emirps</code> is a function.
testString: 'assert(typeof emirps === "function", "<code>emirps</code> is a function.");'
- text: '<code>emirps(20,true)</code> should return <code>[13,17,31,37,71,73,79,97,107,113,149,157,167,179,199,311,337,347,359,389]</code>'
testString: 'assert.deepEqual(emirps(20, true), [13, 17, 31, 37, 71, 73, 79, 97, 107, 113, 149, 157, 167, 179, 199, 311, 337, 347, 359, 389], "<code>emirps(20,true)</code> should return <code>[13,17,31,37,71,73,79,97,107,113,149,157,167,179,199,311,337,347,359,389]</code>");'
testString: assert(typeof emirps === 'function', '<code>emirps</code> is a function.');
- text: <code>emirps(20,true)</code> should return <code>[13,17,31,37,71,73,79,97,107,113,149,157,167,179,199,311,337,347,359,389]</code>
testString: assert.deepEqual(emirps(20, true), [13, 17, 31, 37, 71, 73, 79, 97, 107, 113, 149, 157, 167, 179, 199, 311, 337, 347, 359, 389], '<code>emirps(20,true)</code> should return <code>[13,17,31,37,71,73,79,97,107,113,149,157,167,179,199,311,337,347,359,389]</code>');
- text: <code>emirps(10000)</code> should return <code>948349</code>
testString: 'assert.deepEqual(emirps(10000), 948349, "<code>emirps(10000)</code> should return <code>948349</code>");'
- text: '<code>emirps([7700,8000],true)</code> should return <code>[7717,7757,7817,7841,7867,7879,7901,7927,7949,7951,7963]</code>'
testString: 'assert.deepEqual(emirps([7700, 8000], true), [7717, 7757, 7817, 7841, 7867, 7879, 7901, 7927, 7949, 7951, 7963], "<code>emirps([7700,8000],true)</code> should return <code>[7717,7757,7817,7841,7867,7879,7901,7927,7949,7951,7963]</code>");'
- text: '<code>emirps([7700,8000],true)</code> should return <code>11</code>'
testString: 'assert.deepEqual(emirps([7700, 8000], false), 11, "<code>emirps([7700,8000],true)</code> should return <code>11</code>");'
testString: assert.deepEqual(emirps(10000), 948349, '<code>emirps(10000)</code> should return <code>948349</code>');
- text: <code>emirps([7700,8000],true)</code> should return <code>[7717,7757,7817,7841,7867,7879,7901,7927,7949,7951,7963]</code>
testString: assert.deepEqual(emirps([7700, 8000], true), [7717, 7757, 7817, 7841, 7867, 7879, 7901, 7927, 7949, 7951, 7963], '<code>emirps([7700,8000],true)</code> should return <code>[7717,7757,7817,7841,7867,7879,7901,7927,7949,7951,7963]</code>');
- text: <code>emirps([7700,8000],true)</code> should return <code>11</code>
testString: assert.deepEqual(emirps([7700, 8000], false), 11, '<code>emirps([7700,8000],true)</code> should return <code>11</code>');
```

View File

@ -22,19 +22,19 @@ Task:
```yml
tests:
- text: <code>entropy</code> is a function.
testString: 'assert(typeof entropy === "function", "<code>entropy</code> is a function.");'
testString: assert(typeof entropy === 'function', '<code>entropy</code> is a function.');
- text: <code>entropy("0")</code> should return <code>0</code>
testString: 'assert.equal(entropy("0"), 0, "<code>entropy("0")</code> should return <code>0</code>");'
testString: assert.equal(entropy('0'), 0, '<code>entropy("0")</code> should return <code>0</code>');
- text: <code>entropy("01")</code> should return <code>1</code>
testString: 'assert.equal(entropy("01"), 1, "<code>entropy("01")</code> should return <code>1</code>");'
testString: assert.equal(entropy('01'), 1, '<code>entropy("01")</code> should return <code>1</code>');
- text: <code>entropy("0123")</code> should return <code>2</code>
testString: 'assert.equal(entropy("0123"), 2, "<code>entropy("0123")</code> should return <code>2</code>");'
testString: assert.equal(entropy('0123'), 2, '<code>entropy("0123")</code> should return <code>2</code>');
- text: <code>entropy("01234567")</code> should return <code>3</code>
testString: 'assert.equal(entropy("01234567"), 3, "<code>entropy("01234567")</code> should return <code>3</code>");'
testString: assert.equal(entropy('01234567'), 3, '<code>entropy("01234567")</code> should return <code>3</code>');
- text: <code>entropy("0123456789abcdef")</code> should return <code>4</code>
testString: 'assert.equal(entropy("0123456789abcdef"), 4, "<code>entropy("0123456789abcdef")</code> should return <code>4</code>");'
testString: assert.equal(entropy('0123456789abcdef'), 4, '<code>entropy("0123456789abcdef")</code> should return <code>4</code>');
- text: <code>entropy("1223334444")</code> should return <code>1.8464393446710154</code>
testString: 'assert.equal(entropy("1223334444"), 1.8464393446710154, "<code>entropy("1223334444")</code> should return <code>1.8464393446710154</code>");'
testString: assert.equal(entropy('1223334444'), 1.8464393446710154, '<code>entropy("1223334444")</code> should return <code>1.8464393446710154</code>');
```

View File

@ -28,19 +28,19 @@ challengeType: 5
```yml
tests:
- text: <code>equilibrium</code> is a function.
testString: 'assert(typeof equilibrium === "function", "<code>equilibrium</code> is a function.");'
- text: '<code>equilibrium([-7, 1, 5, 2, -4, 3, 0])</code> should return <code>[3,6]</code>.'
testString: 'assert.deepEqual(equilibrium(tests[0]), ans[0], "<code>equilibrium([-7, 1, 5, 2, -4, 3, 0])</code> should return <code>[3,6]</code>.");'
- text: '<code>equilibrium([2, 4, 6])</code> should return <code>[]</code>.'
testString: 'assert.deepEqual(equilibrium(tests[1]), ans[1], "<code>equilibrium([2, 4, 6])</code> should return <code>[]</code>.");'
- text: '<code>equilibrium([2, 9, 2])</code> should return <code>[1]</code>.'
testString: 'assert.deepEqual(equilibrium(tests[2]), ans[2], "<code>equilibrium([2, 9, 2])</code> should return <code>[1]</code>.");'
- text: '<code>equilibrium([1, -1, 1, -1, 1, -1, 1])</code> should return <code>[0,1,2,3,4,5,6]</code>.'
testString: 'assert.deepEqual(equilibrium(tests[3]), ans[3], "<code>equilibrium([1, -1, 1, -1, 1, -1, 1])</code> should return <code>[0,1,2,3,4,5,6]</code>.");'
- text: '<code>equilibrium([1])</code> should return <code>[0]</code>.'
testString: 'assert.deepEqual(equilibrium(tests[4]), ans[4], "<code>equilibrium([1])</code> should return <code>[0]</code>.");'
- text: '<code>equilibrium([])</code> should return <code>[]</code>.'
testString: 'assert.deepEqual(equilibrium(tests[5]), ans[5], "<code>equilibrium([])</code> should return <code>[]</code>.");'
testString: assert(typeof equilibrium === 'function', '<code>equilibrium</code> is a function.');
- text: <code>equilibrium([-7, 1, 5, 2, -4, 3, 0])</code> should return <code>[3,6]</code>.
testString: assert.deepEqual(equilibrium(equilibriumTests[0]), ans[0], '<code>equilibrium([-7, 1, 5, 2, -4, 3, 0])</code> should return <code>[3,6]</code>.');
- text: <code>equilibrium([2, 4, 6])</code> should return <code>[]</code>.
testString: assert.deepEqual(equilibrium(equilibriumTests[1]), ans[1], '<code>equilibrium([2, 4, 6])</code> should return <code>[]</code>.');
- text: <code>equilibrium([2, 9, 2])</code> should return <code>[1]</code>.
testString: assert.deepEqual(equilibrium(equilibriumTests[2]), ans[2], '<code>equilibrium([2, 9, 2])</code> should return <code>[1]</code>.');
- text: <code>equilibrium([1, -1, 1, -1, 1, -1, 1])</code> should return <code>[0,1,2,3,4,5,6]</code>.
testString: assert.deepEqual(equilibrium(equilibriumTests[3]), ans[3], '<code>equilibrium([1, -1, 1, -1, 1, -1, 1])</code> should return <code>[0,1,2,3,4,5,6]</code>.');
- text: <code>equilibrium([1])</code> should return <code>[0]</code>.
testString: assert.deepEqual(equilibrium(equilibriumTests[4]), ans[4], '<code>equilibrium([1])</code> should return <code>[0]</code>.');
- text: <code>equilibrium([])</code> should return <code>[]</code>.
testString: assert.deepEqual(equilibrium(equilibriumTests[5]), ans[5], '<code>equilibrium([])</code> should return <code>[]</code>.');
```
@ -64,7 +64,15 @@ function equilibrium (a) {
<div id='js-teardown'>
```js
console.info('after the test');
const equilibriumTests =
[[-7, 1, 5, 2, -4, 3, 0], // 3, 6
[2, 4, 6], // empty
[2, 9, 2], // 1
[1, -1, 1, -1, 1, -1, 1], // 0,1,2,3,4,5,6
[1], // 0
[] // empty
];
const ans = [[3, 6], [], [1], [0, 1, 2, 3, 4, 5, 6], [0], []];
```
</div>

View File

@ -61,17 +61,17 @@ one to state if an integer is even.
```yml
tests:
- text: <code>eth_mult</code> is a function.
testString: 'assert(typeof eth_mult === "function", "<code>eth_mult</code> is a function.");'
- text: '<code>eth_mult(17,34)</code> should return <code>578</code>.'
testString: 'assert.equal(eth_mult(17, 34), 578, "<code>eth_mult(17,34)</code> should return <code>578</code>.");'
- text: '<code>eth_mult(23,46)</code> should return <code>1058</code>.'
testString: 'assert.equal(eth_mult(23, 46), 1058, "<code>eth_mult(23,46)</code> should return <code>1058</code>.");'
- text: '<code>eth_mult(12,27)</code> should return <code>324</code>.'
testString: 'assert.equal(eth_mult(12, 27), 324, "<code>eth_mult(12,27)</code> should return <code>324</code>.");'
- text: '<code>eth_mult(56,98)</code> should return <code>5488</code>.'
testString: 'assert.equal(eth_mult(56, 98), 5488, "<code>eth_mult(56,98)</code> should return <code>5488</code>.");'
- text: '<code>eth_mult(63,74)</code> should return <code>4662</code>.'
testString: 'assert.equal(eth_mult(63, 74), 4662, "<code>eth_mult(63,74)</code> should return <code>4662</code>.");'
testString: assert(typeof eth_mult === 'function', '<code>eth_mult</code> is a function.');
- text: <code>eth_mult(17,34)</code> should return <code>578</code>.
testString: assert.equal(eth_mult(17, 34), 578, '<code>eth_mult(17,34)</code> should return <code>578</code>.');
- text: <code>eth_mult(23,46)</code> should return <code>1058</code>.
testString: assert.equal(eth_mult(23, 46), 1058, '<code>eth_mult(23,46)</code> should return <code>1058</code>.');
- text: <code>eth_mult(12,27)</code> should return <code>324</code>.
testString: assert.equal(eth_mult(12, 27), 324, '<code>eth_mult(12,27)</code> should return <code>324</code>.');
- text: <code>eth_mult(56,98)</code> should return <code>5488</code>.
testString: assert.equal(eth_mult(56, 98), 5488, '<code>eth_mult(56,98)</code> should return <code>5488</code>.');
- text: <code>eth_mult(63,74)</code> should return <code>4662</code>.
testString: assert.equal(eth_mult(63, 74), 4662, '<code>eth_mult(63,74)</code> should return <code>4662</code>.');
```

View File

@ -36,15 +36,15 @@ Initial values:
```yml
tests:
- text: <code>eulersMethod</code> is a function.
testString: 'assert(typeof eulersMethod === "function", "<code>eulersMethod</code> is a function.");'
- text: '<code>eulersMethod(0, 100, 100, 10)</code> should return a number.'
testString: 'assert(typeof eulersMethod(0, 100, 100, 10) === "number", "<code>eulersMethod(0, 100, 100, 10)</code> should return a number.");'
- text: '<code>eulersMethod(0, 100, 100, 10)</code> should return 20.0424631833732.'
testString: 'assert.equal(eulersMethod(0, 100, 100, 2), 20.0424631833732, "<code>eulersMethod(0, 100, 100, 10)</code> should return 20.0424631833732.");'
- text: '<code>eulersMethod(0, 100, 100, 10)</code> should return 20.01449963666907.'
testString: 'assert.equal(eulersMethod(0, 100, 100, 5), 20.01449963666907, "<code>eulersMethod(0, 100, 100, 10)</code> should return 20.01449963666907.");'
- text: '<code>eulersMethod(0, 100, 100, 10)</code> should return 20.000472392.'
testString: 'assert.equal(eulersMethod(0, 100, 100, 10), 20.000472392, "<code>eulersMethod(0, 100, 100, 10)</code> should return 20.000472392.");'
testString: assert(typeof eulersMethod === 'function', '<code>eulersMethod</code> is a function.');
- text: <code>eulersMethod(0, 100, 100, 10)</code> should return a number.
testString: assert(typeof eulersMethod(0, 100, 100, 10) === 'number', '<code>eulersMethod(0, 100, 100, 10)</code> should return a number.');
- text: <code>eulersMethod(0, 100, 100, 10)</code> should return 20.0424631833732.
testString: assert.equal(eulersMethod(0, 100, 100, 2), 20.0424631833732, '<code>eulersMethod(0, 100, 100, 10)</code> should return 20.0424631833732.');
- text: <code>eulersMethod(0, 100, 100, 10)</code> should return 20.01449963666907.
testString: assert.equal(eulersMethod(0, 100, 100, 5), 20.01449963666907, '<code>eulersMethod(0, 100, 100, 10)</code> should return 20.01449963666907.');
- text: <code>eulersMethod(0, 100, 100, 10)</code> should return 20.000472392.
testString: assert.equal(eulersMethod(0, 100, 100, 10), 20.000472392, '<code>eulersMethod(0, 100, 100, 10)</code> should return 20.000472392.');
```

View File

@ -21,17 +21,17 @@ $\binom{n}{k} = \frac{n!}{(n-k)!k!} = \frac{n(n-1)(n-2)\ldots(n-k+1)}{k(k-1)(k-2
```yml
tests:
- text: <code>binom</code> is a function.
testString: 'assert(typeof binom === "function", "<code>binom</code> is a function.");'
- text: '<code>binom(5,3)</code> should return 10.'
testString: 'assert.equal(binom(5, 3), 10, "<code>binom(5,3)</code> should return 10.");'
- text: '<code>binom(7,2)</code> should return 21.'
testString: 'assert.equal(binom(7, 2), 21, "<code>binom(7,2)</code> should return 21.");'
- text: '<code>binom(10,4)</code> should return 210.'
testString: 'assert.equal(binom(10, 4), 210, "<code>binom(10,4)</code> should return 210.");'
- text: '<code>binom(6,1)</code> should return 6.'
testString: 'assert.equal(binom(6, 1), 6, "<code>binom(6,1)</code> should return 6.");'
- text: '<code>binom(12,8)</code> should return 495.'
testString: 'assert.equal(binom(12, 8), 495, "<code>binom(12,8)</code> should return 495.");'
testString: assert(typeof binom === 'function', '<code>binom</code> is a function.');
- text: <code>binom(5,3)</code> should return 10.
testString: assert.equal(binom(5, 3), 10, '<code>binom(5,3)</code> should return 10.');
- text: <code>binom(7,2)</code> should return 21.
testString: assert.equal(binom(7, 2), 21, '<code>binom(7,2)</code> should return 21.');
- text: <code>binom(10,4)</code> should return 210.
testString: assert.equal(binom(10, 4), 210, '<code>binom(10,4)</code> should return 210.');
- text: <code>binom(6,1)</code> should return 6.
testString: assert.equal(binom(6, 1), 6, '<code>binom(6,1)</code> should return 6.');
- text: <code>binom(12,8)</code> should return 495.
testString: assert.equal(binom(12, 8), 495, '<code>binom(12,8)</code> should return 495.');
```

View File

@ -124,17 +124,17 @@ state C, symbol 1 => write 1, move left, halt0C1 -> H01
```yml
tests:
- text: <code>markov</code> is a function.
testString: 'assert(typeof markov === "function", "<code>markov</code> is a function.");'
- text: '<code>markov(["A -> apple","B -> bag","S -> shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")</code> should return "I bought a bag of apples from my brother.".'
testString: 'assert.deepEqual(markov(rules[0],tests[0]),outputs[0],"<code>markov(["A -> apple","B -> bag","S -> shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")</code> should return "I bought a bag of apples from my brother.".");'
- text: '<code>markov(["A -> apple","B -> bag","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")</code> should return "I bought a bag of apples from T shop.".'
testString: 'assert.deepEqual(markov(rules[1],tests[1]),outputs[1],"<code>markov(["A -> apple","B -> bag","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")</code> should return "I bought a bag of apples from T shop.".");'
- text: '<code>markov(["A -> apple","WWWW -> with","Bgage -> ->.*","B -> bag","->.* -> money","W -> WW","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As W my Bgage from T S.")</code> should return "I bought a bag of apples with my money from T shop.".'
testString: 'assert.deepEqual(markov(rules[2],tests[2]),outputs[2],"<code>markov(["A -> apple","WWWW -> with","Bgage -> ->.*","B -> bag","->.* -> money","W -> WW","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As W my Bgage from T S.")</code> should return "I bought a bag of apples with my money from T shop.".");'
- text: '<code>markov(["_+1 -> _1+","1+1 -> 11+","1! -> !1",",! -> !+","_! -> _","1*1 -> x,@y","1x -> xX","X, -> 1,1","X1 -> 1X","_x -> _X",",x -> ,X","y1 -> 1y","y_ -> _","1@1 -> x,@y","1@_ -> @_",",@_ -> !_","++ -> +","_1 -> 1","1+_ -> 1","_+_ -> "],"_1111*11111_")</code> should return "11111111111111111111".'
testString: 'assert.deepEqual(markov(rules[3],tests[3]),outputs[3],"<code>markov(["_+1 -> _1+","1+1 -> 11+","1! -> !1",",! -> !+","_! -> _","1*1 -> x,@y","1x -> xX","X, -> 1,1","X1 -> 1X","_x -> _X",",x -> ,X","y1 -> 1y","y_ -> _","1@1 -> x,@y","1@_ -> @_",",@_ -> !_","++ -> +","_1 -> 1","1+_ -> 1","_+_ -> "],"_1111*11111_")</code> should return "11111111111111111111".");'
- text: '<code>markov(["A0 -> 1B","0A1 -> C01","1A1 -> C11","0B0 -> A01","1B0 -> A11","B1 -> 1B","0C0 -> B01","1C0 -> B11","0C1 -> H01","1C1 -> H11"],"")</code> should return "00011H1111000".'
testString: 'assert.deepEqual(markov(rules[4],tests[4]),outputs[4],"<code>markov(["A0 -> 1B","0A1 -> C01","1A1 -> C11","0B0 -> A01","1B0 -> A11","B1 -> 1B","0C0 -> B01","1C0 -> B11","0C1 -> H01","1C1 -> H11"],"")</code> should return "00011H1111000".");'
testString: assert(typeof markov === 'function', '<code>markov</code> is a function.');
- text: <code>markov(["A -> apple","B -> bag","S -> shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")</code> should return "I bought a bag of apples from my brother.".
testString: assert.deepEqual(markov(rules[0],tests[0]),outputs[0],'<code>markov(["A -> apple","B -> bag","S -> shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")</code> should return "I bought a bag of apples from my brother.".');
- text: <code>markov(["A -> apple","B -> bag","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")</code> should return "I bought a bag of apples from T shop.".
testString: assert.deepEqual(markov(rules[1],tests[1]),outputs[1],'<code>markov(["A -> apple","B -> bag","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")</code> should return "I bought a bag of apples from T shop.".');
- text: <code>markov(["A -> apple","WWWW -> with","Bgage -> ->.*","B -> bag","->.* -> money","W -> WW","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As W my Bgage from T S.")</code> should return "I bought a bag of apples with my money from T shop.".
testString: assert.deepEqual(markov(rules[2],tests[2]),outputs[2],'<code>markov(["A -> apple","WWWW -> with","Bgage -> ->.*","B -> bag","->.* -> money","W -> WW","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As W my Bgage from T S.")</code> should return "I bought a bag of apples with my money from T shop.".');
- text: <code>markov(["_+1 -> _1+","1+1 -> 11+","1! -> !1",",! -> !+","_! -> _","1*1 -> x,@y","1x -> xX","X, -> 1,1","X1 -> 1X","_x -> _X",",x -> ,X","y1 -> 1y","y_ -> _","1@1 -> x,@y","1@_ -> @_",",@_ -> !_","++ -> +","_1 -> 1","1+_ -> 1","_+_ -> "],"_1111*11111_")</code> should return "11111111111111111111".
testString: assert.deepEqual(markov(rules[3],tests[3]),outputs[3],'<code>markov(["_+1 -> _1+","1+1 -> 11+","1! -> !1",",! -> !+","_! -> _","1*1 -> x,@y","1x -> xX","X, -> 1,1","X1 -> 1X","_x -> _X",",x -> ,X","y1 -> 1y","y_ -> _","1@1 -> x,@y","1@_ -> @_",",@_ -> !_","++ -> +","_1 -> 1","1+_ -> 1","_+_ -> "],"_1111*11111_")</code> should return "11111111111111111111".');
- text: <code>markov(["A0 -> 1B","0A1 -> C01","1A1 -> C11","0B0 -> A01","1B0 -> A11","B1 -> 1B","0C0 -> B01","1C0 -> B11","0C1 -> H01","1C1 -> H11"],"")</code> should return "00011H1111000".
testString: assert.deepEqual(markov(rules[4],tests[4]),outputs[4],'<code>markov(["A0 -> 1B","0A1 -> C01","1A1 -> C11","0B0 -> A01","1B0 -> A11","B1 -> 1B","0C0 -> B01","1C0 -> B11","0C1 -> H01","1C1 -> H11"],"")</code> should return "00011H1111000".');
```

View File

@ -43,15 +43,15 @@ challengeType: 5
```yml
tests:
- text: <code>brain(bye)</code> should retuen a string
testString: 'assert(typeof brain(bye) === "string", "<code>brain(bye)</code> should return a string");'
- text: '<code>brain("++++++[>++++++++++<-]>+++++.")</code should return "A"'
testString: 'assert.equal(brain("++++++[>++++++++++<-]>+++++."),"A", "<code>brain("++++++[>++++++++++<-]>+++++.")</code should return "A"");'
- text: '<code>brain(bye)</code> should return <code>Goodbye, World!\\r\\n</code>'
testString: 'assert.equal(brain(bye), "Goodbye, World!\r\n", "<code>brain(bye)</code> should return <code>Goodbye, World!\\r\\n</code>");'
testString: assert(typeof brain(bye) === 'string', '<code>brain(bye)</code> should return a string');
- text: <code>brain("++++++[>++++++++++<-]>+++++.")</code should return "A"
testString: assert.equal(brain("++++++[>++++++++++<-]>+++++."),"A", '<code>brain("++++++[>++++++++++<-]>+++++.")</code should return "A"');
- text: <code>brain(bye)</code> should return <code>Goodbye, World!\\r\\n</code>
testString: assert.equal(brain(bye), 'Goodbye, World!\r\n', '<code>brain(bye)</code> should return <code>Goodbye, World!\\r\\n</code>');
- text: <code>brain(hello)</code> should return <code>Hello World!\\n</code>'
testString: 'assert.equal(brain(hello), "Hello World!\n", "<code>brain(hello)</code> should return <code>Hello World!\\n</code>");'
- text: '<code>brain(fib)</code> should return <code>1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89</code>'
testString: 'assert.equal(brain(fib), "1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89", "<code>brain(fib)</code> should return <code>1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89</code>");'
testString: assert.equal(brain(hello), "Hello World!\n", '<code>brain(hello)</code> should return <code>Hello World!\\n</code>');
- text: <code>brain(fib)</code> should return <code>1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89</code>
testString: assert.equal(brain(fib), "1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89", '<code>brain(fib)</code> should return <code>1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89</code>');
```

View File

@ -20,15 +20,15 @@ challengeType: 5
```yml
tests:
- text: <code>primeGenerator</code> is a function.
testString: 'assert(typeof primeGenerator === "function", "<code>primeGenerator</code> is a function.");'
testString: assert(typeof primeGenerator === 'function', '<code>primeGenerator</code> is a function.');
- text: <code>primeGenerator</code> is a function.
testString: 'assert.deepEqual(primeGenerator(20, true), [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71], "<code>primeGenerator</code> is a function.");'
testString: assert.deepEqual(primeGenerator(20, true), [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71], '<code>primeGenerator</code> is a function.');
- text: <code>primeGenerator</code> is a function.
testString: 'assert.deepEqual(primeGenerator([100, 150], true), [101, 103, 107, 109, 113, 127, 131, 137, 139, 149], "<code>primeGenerator</code> is a function.");'
testString: assert.deepEqual(primeGenerator([100, 150], true), [101, 103, 107, 109, 113, 127, 131, 137, 139, 149], '<code>primeGenerator</code> is a function.');
- text: <code>primeGenerator</code> is a function.
testString: 'assert.equal(primeGenerator([7700, 8000], false), 30, "<code>primeGenerator</code> is a function.");'
testString: assert.equal(primeGenerator([7700, 8000], false), 30, '<code>primeGenerator</code> is a function.');
- text: <code>primeGenerator</code> is a function.
testString: 'assert.equal(primeGenerator(10000, false), 104729, "<code>primeGenerator</code> is a function.");'
testString: assert.equal(primeGenerator(10000, false), 104729, '<code>primeGenerator</code> is a function.');
```

View File

@ -30,15 +30,15 @@ For example :
```yml
tests:
- text: <code>factorial</code> is a function.
testString: 'assert(typeof factorial === "function", "<code>factorial</code> is a function.");'
testString: assert(typeof factorial === 'function', '<code>factorial</code> is a function.');
- text: <code>factorial(2)</code> should return a number.
testString: 'assert(typeof factorial(2) === "number", "<code>factorial(2)</code> should return a number.");'
testString: assert(typeof factorial(2) === 'number', '<code>factorial(2)</code> should return a number.');
- text: <code>factorial(3)</code> should return 6.")
testString: 'assert.equal(factorial(3),results[0],"<code>factorial(3)</code> should return 6.");'
testString: assert.equal(factorial(3),results[0],"<code>factorial(3)</code> should return 6.");
- text: <code>factorial(3)</code> should return 120.")
testString: 'assert.equal(factorial(5),results[1],"<code>factorial(3)</code> should return 120.");'
- text: '<code>factorial(3)</code> should return 3,628,800.")'
testString: 'assert.equal(factorial(10),results[2],"<code>factorial(3)</code> should return 3,628,800.");'
testString: assert.equal(factorial(5),results[1],"<code>factorial(3)</code> should return 120.");
- text: <code>factorial(3)</code> should return 3,628,800.")
testString: assert.equal(factorial(10),results[2],"<code>factorial(3)</code> should return 3,628,800.");
```
@ -62,7 +62,7 @@ function factorial (n) {
<div id='js-teardown'>
```js
console.info('after the test');
const results=[6,120,3628800];
```
</div>

View File

@ -50,15 +50,15 @@ Related tasks:
```yml
tests:
- text: <code>check_mersenne</code> is a function.
testString: 'assert(typeof check_mersenne === "function", "<code>check_mersenne</code> is a function.");'
testString: assert(typeof check_mersenne === 'function', '<code>check_mersenne</code> is a function.');
- text: <code>check_mersenne(3)</code> should return a string.
testString: 'assert(typeof check_mersenne(3) == "string", "<code>check_mersenne(3)</code> should return a string.");'
testString: assert(typeof check_mersenne(3) == 'string', '<code>check_mersenne(3)</code> should return a string.');
- text: <code>check_mersenne(3)</code> should return "M3 = 2^3-1 is prime".
testString: 'assert.equal(check_mersenne(3),"M3 = 2^3-1 is prime","<code>check_mersenne(3)</code> should return "M3 = 2^3-1 is prime".");'
testString: assert.equal(check_mersenne(3),"M3 = 2^3-1 is prime",'<code>check_mersenne(3)</code> should return "M3 = 2^3-1 is prime".');
- text: <code>check_mersenne(23)</code> should return "M23 = 2^23-1 is composite with factor 47".
testString: 'assert.equal(check_mersenne(23),"M23 = 2^23-1 is composite with factor 47","<code>check_mersenne(23)</code> should return "M23 = 2^23-1 is composite with factor 47".");'
testString: assert.equal(check_mersenne(23),"M23 = 2^23-1 is composite with factor 47",'<code>check_mersenne(23)</code> should return "M23 = 2^23-1 is composite with factor 47".');
- text: <code>check_mersenne(929)</code> should return "M929 = 2^929-1 is composite with factor 13007
testString: 'assert.equal(check_mersenne(929),"M929 = 2^929-1 is composite with factor 13007","<code>check_mersenne(929)</code> should return "M929 = 2^929-1 is composite with factor 13007");'
testString: assert.equal(check_mersenne(929),"M929 = 2^929-1 is composite with factor 13007",'<code>check_mersenne(929)</code> should return "M929 = 2^929-1 is composite with factor 13007');
```

View File

@ -21,13 +21,13 @@ challengeType: 5
```yml
tests:
- text: <code>factors</code> is a function.
testString: 'assert(typeof factors === "function", "<code>factors</code> is a function.");'
- text: '<code>factors(45)</code> should return <code>[1,3,5,9,15,45]</code>.'
testString: 'assert.deepEqual(factors(45), ans[0], "<code>factors(45)</code> should return <code>[1,3,5,9,15,45]</code>.");'
- text: '<code>factors(53)</code> should return <code>[1,53]</code>.'
testString: 'assert.deepEqual(factors(53), ans[1], "<code>factors(53)</code> should return <code>[1,53]</code>.");'
- text: '<code>factors(64)</code> should return <code>[1,2,4,8,16,32,64]</code>.'
testString: 'assert.deepEqual(factors(64), ans[2], "<code>factors(64)</code> should return <code>[1,2,4,8,16,32,64]</code>.");'
testString: assert(typeof factors === 'function', '<code>factors</code> is a function.');
- text: <code>factors(45)</code> should return <code>[1,3,5,9,15,45]</code>.
testString: assert.deepEqual(factors(45), ans[0], '<code>factors(45)</code> should return <code>[1,3,5,9,15,45]</code>.');
- text: <code>factors(53)</code> should return <code>[1,53]</code>.
testString: assert.deepEqual(factors(53), ans[1], '<code>factors(53)</code> should return <code>[1,53]</code>.');
- text: <code>factors(64)</code> should return <code>[1,2,4,8,16,32,64]</code>.
testString: assert.deepEqual(factors(64), ans[2], '<code>factors(64)</code> should return <code>[1,2,4,8,16,32,64]</code>.');
```
@ -51,7 +51,7 @@ function factors (num) {
<div id='js-teardown'>
```js
console.info('after the test');
const ans=[[1,3,5,9,15,45],[1,53],[1,2,4,8,16,32,64]];
```
</div>

View File

@ -32,15 +32,15 @@ challengeType: 5
```yml
tests:
- text: <code>farey</code> is a function.
testString: 'assert(typeof farey === "function", "<code>farey</code> is a function.");'
testString: assert(typeof farey === 'function', '<code>farey</code> is a function.');
- text: <code>farey(3)</code> should return an array
testString: 'assert(Array.isArray(farey(3)), "<code>farey(3)</code> should return an array");'
- text: '<code>farey(3)</code> should return <code>["1/3","1/2","2/3"]</code>'
testString: 'assert.deepEqual(farey(3), ["1/3","1/2","2/3"], "<code>farey(3)</code> should return <code>["1/3","1/2","2/3"]</code>");'
- text: '<code>farey(4)</code> should return <code>["1/4","1/3","1/2","2/4","2/3","3/4"]</code>'
testString: 'assert.deepEqual(farey(4), ["1/4","1/3","1/2","2/4","2/3","3/4"], "<code>farey(4)</code> should return <code>["1/4","1/3","1/2","2/4","2/3","3/4"]</code>");'
- text: '<code>farey(5)</code> should return <code>["1/5","1/4","1/3","2/5","1/2","2/4","3/5","2/3","3/4","4/5"]</code>'
testString: 'assert.deepEqual(farey(5), ["1/5","1/4","1/3","2/5","1/2","2/4","3/5","2/3","3/4","4/5"], "<code>farey(5)</code> should return <code>["1/5","1/4","1/3","2/5","1/2","2/4","3/5","2/3","3/4","4/5"]</code>");'
testString: assert(Array.isArray(farey(3)), '<code>farey(3)</code> should return an array');
- text: <code>farey(3)</code> should return <code>["1/3","1/2","2/3"]</code>
testString: assert.deepEqual(farey(3), ["1/3","1/2","2/3"], '<code>farey(3)</code> should return <code>["1/3","1/2","2/3"]</code>');
- text: <code>farey(4)</code> should return <code>["1/4","1/3","1/2","2/4","2/3","3/4"]</code>
testString: assert.deepEqual(farey(4), ["1/4","1/3","1/2","2/4","2/3","3/4"], '<code>farey(4)</code> should return <code>["1/4","1/3","1/2","2/4","2/3","3/4"]</code>');
- text: <code>farey(5)</code> should return <code>["1/5","1/4","1/3","2/5","1/2","2/4","3/5","2/3","3/4","4/5"]</code>
testString: assert.deepEqual(farey(5), ["1/5","1/4","1/3","2/5","1/2","2/4","3/5","2/3","3/4","4/5"], '<code>farey(5)</code> should return <code>["1/5","1/4","1/3","2/5","1/2","2/4","3/5","2/3","3/4","4/5"]</code>');
```

View File

@ -48,21 +48,21 @@ For general $n>2$ we have the Fibonacci $n$-step sequence - $F_k^n$; with initia
```yml
tests:
- text: <code>fib_luc</code> is a function.
testString: 'assert(typeof fib_luc === "function", "<code>fib_luc</code> is a function.");'
- text: '<code>fib_luc(2,10,"f")</code> should return <code>[1,1,2,3,5,8,13,21,34,55]</code>.'
testString: 'assert.deepEqual(fib_luc(2,10,"f"),ans[0],"<code>fib_luc(2,10,"f")</code> should return <code>[1,1,2,3,5,8,13,21,34,55]</code>.");'
- text: '<code>fib_luc(3,15,"f")</code> should return <code>[1,1,2,4,7,13,24,44,81,149,274,504,927,1705,3136]</code>.'
testString: 'assert.deepEqual(fib_luc(3,15,"f"),ans[1],"<code>fib_luc(3,15,"f")</code> should return <code>[1,1,2,4,7,13,24,44,81,149,274,504,927,1705,3136]</code>.");'
- text: '<code>fib_luc(4,15,"f")</code> should return <code>[1,1,2,4,8,15,29,56,108,208,401,773,1490,2872,5536]</code>.'
testString: 'assert.deepEqual(fib_luc(4,15,"f"),ans[2],"<code>fib_luc(4,15,"f")</code> should return <code>[1,1,2,4,8,15,29,56,108,208,401,773,1490,2872,5536]</code>.");'
- text: '<code>fib_luc(2,10,"l")</code> should return <code>[ 2, 1, 3, 4, 7, 11, 18, 29, 47, 76]</code>.'
testString: 'assert.deepEqual(fib_luc(2,10,"l"),ans[3],"<code>fib_luc(2,10,"l")</code> should return <code>[ 2, 1, 3, 4, 7, 11, 18, 29, 47, 76]</code>.");'
- text: '<code>fib_luc(3,15,"l")</code> should return <code>[ 2, 1, 3, 6, 10, 19, 35, 64, 118, 217, 399, 734, 1350, 2483, 4567 ]</code>.'
testString: 'assert.deepEqual(fib_luc(3,15,"l"),ans[4],"<code>fib_luc(3,15,"l")</code> should return <code>[ 2, 1, 3, 6, 10, 19, 35, 64, 118, 217, 399, 734, 1350, 2483, 4567 ]</code>.");'
- text: '<code>fib_luc(4,15,"l")</code> should return <code>[ 2, 1, 3, 6, 12, 22, 43, 83, 160, 308, 594, 1145, 2207, 4254, 8200 ]</code>.'
testString: 'assert.deepEqual(fib_luc(4,15,"l"),ans[5],"<code>fib_luc(4,15,"l")</code> should return <code>[ 2, 1, 3, 6, 12, 22, 43, 83, 160, 308, 594, 1145, 2207, 4254, 8200 ]</code>.");'
- text: '<code>fib_luc(5,15,"l")</code> should return <code>[ 2, 1, 3, 6, 12, 24, 46, 91, 179, 352, 692, 1360, 2674, 5257, 10335 ]</code>.'
testString: 'assert.deepEqual(fib_luc(5,15,"l"),ans[6],"<code>fib_luc(5,15,"l")</code> should return <code>[ 2, 1, 3, 6, 12, 24, 46, 91, 179, 352, 692, 1360, 2674, 5257, 10335 ]</code>.");'
testString: assert(typeof fib_luc === 'function', '<code>fib_luc</code> is a function.');
- text: <code>fib_luc(2,10,"f")</code> should return <code>[1,1,2,3,5,8,13,21,34,55]</code>.
testString: assert.deepEqual(fib_luc(2,10,"f"),ans[0],'<code>fib_luc(2,10,"f")</code> should return <code>[1,1,2,3,5,8,13,21,34,55]</code>.');
- text: <code>fib_luc(3,15,"f")</code> should return <code>[1,1,2,4,7,13,24,44,81,149,274,504,927,1705,3136]</code>.
testString: assert.deepEqual(fib_luc(3,15,"f"),ans[1],'<code>fib_luc(3,15,"f")</code> should return <code>[1,1,2,4,7,13,24,44,81,149,274,504,927,1705,3136]</code>.');
- text: <code>fib_luc(4,15,"f")</code> should return <code>[1,1,2,4,8,15,29,56,108,208,401,773,1490,2872,5536]</code>.
testString: assert.deepEqual(fib_luc(4,15,"f"),ans[2],'<code>fib_luc(4,15,"f")</code> should return <code>[1,1,2,4,8,15,29,56,108,208,401,773,1490,2872,5536]</code>.');
- text: <code>fib_luc(2,10,"l")</code> should return <code>[ 2, 1, 3, 4, 7, 11, 18, 29, 47, 76]</code>.
testString: assert.deepEqual(fib_luc(2,10,"l"),ans[3],'<code>fib_luc(2,10,"l")</code> should return <code>[ 2, 1, 3, 4, 7, 11, 18, 29, 47, 76]</code>.');
- text: <code>fib_luc(3,15,"l")</code> should return <code>[ 2, 1, 3, 6, 10, 19, 35, 64, 118, 217, 399, 734, 1350, 2483, 4567 ]</code>.
testString: assert.deepEqual(fib_luc(3,15,"l"),ans[4],'<code>fib_luc(3,15,"l")</code> should return <code>[ 2, 1, 3, 6, 10, 19, 35, 64, 118, 217, 399, 734, 1350, 2483, 4567 ]</code>.');
- text: <code>fib_luc(4,15,"l")</code> should return <code>[ 2, 1, 3, 6, 12, 22, 43, 83, 160, 308, 594, 1145, 2207, 4254, 8200 ]</code>.
testString: assert.deepEqual(fib_luc(4,15,"l"),ans[5],'<code>fib_luc(4,15,"l")</code> should return <code>[ 2, 1, 3, 6, 12, 22, 43, 83, 160, 308, 594, 1145, 2207, 4254, 8200 ]</code>.');
- text: <code>fib_luc(5,15,"l")</code> should return <code>[ 2, 1, 3, 6, 12, 24, 46, 91, 179, 352, 692, 1360, 2674, 5257, 10335 ]</code>.
testString: assert.deepEqual(fib_luc(5,15,"l"),ans[6],'<code>fib_luc(5,15,"l")</code> should return <code>[ 2, 1, 3, 6, 12, 24, 46, 91, 179, 352, 692, 1360, 2674, 5257, 10335 ]</code>.');
```
@ -86,7 +86,13 @@ function fib_luc (n, len, w) {
<div id='js-teardown'>
```js
console.info('after the test');
const ans = [[1,1,2,3,5,8,13,21,34,55],
[1,1,2,4,7,13,24,44,81,149,274,504,927,1705,3136],
[1,1,2,4,8,15,29,56,108,208,401,773,1490,2872,5536],
[ 2, 1, 3, 4, 7, 11, 18, 29, 47, 76],
[ 2, 1, 3, 6, 10, 19, 35, 64, 118, 217, 399, 734, 1350, 2483, 4567 ],
[ 2, 1, 3, 6, 12, 22, 43, 83, 160, 308, 594, 1145, 2207, 4254, 8200 ],
[ 2, 1, 3, 6, 12, 24, 46, 91, 179, 352, 692, 1360, 2674, 5257, 10335 ]];
```
</div>

View File

@ -25,15 +25,15 @@ challengeType: 5
```yml
tests:
- text: <code>fibonacci</code> is a function.
testString: 'assert(typeof fibonacci === "function", "<code>fibonacci</code> is a function.");'
testString: assert(typeof fibonacci === 'function', '<code>fibonacci</code> is a function.');
- text: <code>fibonacci(2)</code> should return a number.
testString: 'assert(typeof fibonacci(2) == "number", "<code>fibonacci(2)</code> should return a number.");'
testString: assert(typeof fibonacci(2) == 'number', '<code>fibonacci(2)</code> should return a number.');
- text: <code>fibonacci(3)</code> should return 1.")
testString: 'assert.equal(fibonacci(3),1,"<code>fibonacci(3)</code> should return 1.");'
testString: assert.equal(fibonacci(3),1,"<code>fibonacci(3)</code> should return 1.");
- text: <code>fibonacci(5)</code> should return 3.")
testString: 'assert.equal(fibonacci(5),3,"<code>fibonacci(5)</code> should return 3.");'
testString: assert.equal(fibonacci(5),3,"<code>fibonacci(5)</code> should return 3.");
- text: <code>fibonacci(10)</code> should return 34.")
testString: 'assert.equal(fibonacci(10),34,"<code>fibonacci(10)</code> should return 34.");'
testString: assert.equal(fibonacci(10),34,"<code>fibonacci(10)</code> should return 34.");
```

View File

@ -23,11 +23,11 @@ challengeType: 5
```yml
tests:
- text: <code>fibWord</code> is a function.
testString: 'assert(typeof fibWord === "function", "<code>fibWord</code> is a function.");'
testString: assert(typeof fibWord === 'function', '<code>fibWord</code> is a function.');
- text: <code>fibWord(5)</code> should return an array.
testString: 'assert(Array.isArray(fibWord(5)),"<code>fibWord(5)</code> should return an array.");'
testString: assert(Array.isArray(fibWord(5)),'<code>fibWord(5)</code> should return an array.');
- text: <code>fibWord(5)</code> should return <code>'+JSON.stringify(ans)+'</code>.
testString: 'assert.deepEqual(fibWord(5),ans,"<code>fibWord(5)</code> should return <code>"+JSON.stringify(ans)+"</code>.");'
testString: assert.deepEqual(fibWord(5),ans,'<code>fibWord(5)</code> should return <code>'+JSON.stringify(ans)+'</code>.');
```
@ -51,7 +51,15 @@ function fibWord (n) {
<div id='js-teardown'>
```js
console.info('after the test');
let ans=[ { N: 1, Length: 1, Entropy: 0, Word: '1' },
{ N: 2, Length: 1, Entropy: 0, Word: '0' },
{ N: 3, Length: 2, Entropy: 1, Word: '01' },
{ N: 4, Length: 3, Entropy: 0.9182958340544896, Word: '010' },
{ N: 5, Length: 5, Entropy: 0.9709505944546688, Word: '01001' }];
```
</div>

View File

@ -26,19 +26,19 @@ challengeType: 3
```yml
tests:
- text: <code>fractran</code> should be a function.
testString: 'assert(typeof fractran=="function","<code>fractran</code> should be a function.");'
- text: '<code>fractran(""+tests[0]+"")</code> should return an array.'
testString: 'assert(Array.isArray(fractran(tests[0])),"<code>fractran(""+tests[0]+"")</code> should return an array.");'
- text: '<code>fractran(""+tests[0]+"")</code> should return <code>"+JSON.stringify(results[0])+"</code>.'
testString: 'assert.deepEqual(fractran(tests[0]),results[0],"<code>fractran(""+tests[0]+"")</code> should return <code>"+JSON.stringify(results[0])+"</code>.");'
- text: '<code>fractran(""+tests[1]+"")</code> should return <code>"+JSON.stringify(results[1])+"</code>.'
testString: 'assert.deepEqual(fractran(tests[1]),results[1],"<code>fractran(""+tests[1]+"")</code> should return <code>"+JSON.stringify(results[1])+"</code>.");'
- text: '<code>fractran(""+tests[2]+"")</code> should return <code>"+JSON.stringify(results[2])+"</code>.'
testString: 'assert.deepEqual(fractran(tests[2]),results[2],"<code>fractran(""+tests[2]+"")</code> should return <code>"+JSON.stringify(results[2])+"</code>.");'
- text: '<code>fractran(""+tests[3]+"")</code> should return <code>"+JSON.stringify(results[3])+"</code>.'
testString: 'assert.deepEqual(fractran(tests[3]),results[3],"<code>fractran(""+tests[3]+"")</code> should return <code>"+JSON.stringify(results[3])+"</code>.");'
- text: '<code>fractran(""+tests[4]+"")</code> should return <code>"+JSON.stringify(results[4])+"</code>.'
testString: 'assert.deepEqual(fractran(tests[4]),results[4],"<code>fractran(""+tests[4]+"")</code> should return <code>"+JSON.stringify(results[4])+"</code>.");'
testString: assert(typeof fractran=='function','<code>fractran</code> should be a function.');
- text: <code>fractran("3/2, 1/3")</code> should return an array.
testString: assert(Array.isArray(fractran('3/2, 1/3')),'<code>fractran("3/2, 1/3")</code> should return an array.');
- text: <code>fractran("3/2, 1/3")</code> should return <code>[ 2, 3, 1 ]</code>.
testString: assert.deepEqual(fractran('3/2, 1/3'), [ 2, 3, 1 ],'<code>fractran("3/2, 1/3")</code> should return <code>[ 2, 3, 1 ]</code>.');
- text: <code>fractran("3/2, 5/3, 1/5")</code> should return <code>[ 2, 3, 5, 1 ]</code>.
testString: assert.deepEqual(fractran('3/2, 5/3, 1/5'), [ 2, 3, 5, 1 ],'<code>fractran("3/2, 5/3, 1/5")</code> should return <code>[ 2, 3, 5, 1 ]</code>.');
- text: <code>fractran("3/2, 6/3")</code> should return <code>[ 2, 3, 6, 9, 18, 27, 54, 81, 162, 243 ]</code>.
testString: assert.deepEqual(fractran('3/2, 6/3'), [ 2, 3, 6, 9, 18, 27, 54, 81, 162, 243 ],'<code>fractran("3/2, 6/3")</code> should return <code>[ 2, 3, 6, 9, 18, 27, 54, 81, 162, 243 ]</code>.');
- text: <code>fractran("2/7, 7/2")</code> should return <code>[ 2, 7, 2, 7, 2, 7, 2, 7, 2, 7 ]</code>.
testString: assert.deepEqual(fractran('2/7, 7/2'), [ 2, 7, 2, 7, 2, 7, 2, 7, 2, 7 ],'<code>fractran("2/7, 7/2")</code> should return <code>[ 2, 7, 2, 7, 2, 7, 2, 7, 2, 7 ]</code>.');
- text: <code>fractran("17/91, 78/85, 19/51, 23/38, 29/33, 77/29, 95/23, 77/19, 1/17, 11/13, 13/11, 15/14, 15/2, 55/1")</code> should return <code>[ 2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290 ]</code>.
testString: assert.deepEqual(fractran('17/91, 78/85, 19/51, 23/38, 29/33, 77/29, 95/23, 77/19, 1/17, 11/13, 13/11, 15/14, 15/2, 55/1'), [ 2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290 ],'<code>fractran("17/91, 78/85, 19/51, 23/38, 29/33, 77/29, 95/23, 77/19, 1/17, 11/13, 13/11, 15/14, 15/2, 55/1")</code> should return <code>[ 2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290 ]</code>.');
```
@ -57,16 +57,6 @@ function fractran (progStr) {
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution

View File

@ -22,19 +22,19 @@ The Gamma function can be defined as:
```yml
tests:
- text: <code>gamma</code> should be a function.
testString: 'assert(typeof gamma=="function","<code>gamma</code> should be a function.")'
- text: '<code>gamma("+tests[0]+")</code> should return a number.'
testString: 'assert(typeof gamma(tests[0])=="number","<code>gamma("+tests[0]+")</code> should return a number.")'
- text: '<code>gamma("+tests[0]+")</code> should return <code>"+results[0]+"</code>.'
testString: 'assert.equal(gamma(tests[0]),results[0],"<code>gamma("+tests[0]+")</code> should return <code>"+results[0]+"</code>.")'
- text: '<code>gamma("+tests[1]+")</code> should return <code>"+results[1]+"</code>.'
testString: 'assert.equal(gamma(tests[1]),results[1],"<code>gamma("+tests[1]+")</code> should return <code>"+results[1]+"</code>.")'
- text: '<code>gamma("+tests[2]+")</code> should return <code>"+results[2]+"</code>.'
testString: 'assert.equal(gamma(tests[2]),results[2],"<code>gamma("+tests[2]+")</code> should return <code>"+results[2]+"</code>.")'
- text: '<code>gamma("+tests[3]+")</code> should return <code>"+results[3]+"</code>.'
testString: 'assert.equal(gamma(tests[3]),results[3],"<code>gamma("+tests[3]+")</code> should return <code>"+results[3]+"</code>.")'
- text: '<code>gamma("+tests[4]+")</code> should return <code>"+results[4]+"</code>.'
testString: 'assert.equal(gamma(tests[4]),results[4],"<code>gamma("+tests[4]+")</code> should return <code>"+results[4]+"</code>.")'
testString: assert(typeof gamma=='function','<code>gamma</code> should be a function.')
- text: <code>gamma(.1)</code> should return a number.
testString: assert(typeof gamma(.1)=='number','<code>gamma(.1)</code> should return a number.')
- text: <code>gamma(.1)</code> should return <code>9.513507698668736</code>.
testString: assert.equal(gamma(.1), 9.513507698668736,'<code>gamma(.1)</code> should return <code>9.513507698668736</code>.')
- text: <code>gamma(.2)</code> should return <code>4.590843711998803</code>.
testString: assert.equal(gamma(.2), 4.590843711998803,'<code>gamma(.2)</code> should return <code>4.590843711998803</code>.')
- text: <code>gamma(.3)</code> should return <code>2.9915689876875904</code>.
testString: assert.equal(gamma(.3), 2.9915689876875904,'<code>gamma(.3)</code> should return <code>2.9915689876875904</code>.')
- text: <code>gamma(.4)</code> should return <code>2.218159543757687</code>.
testString: assert.equal(gamma(.4), 2.218159543757687,'<code>gamma(.4)</code> should return <code>2.218159543757687</code>.')
- text: <code>gamma(.5)</code> should return <code>1.7724538509055159</code>.
testString: assert.equal(gamma(.5), 1.7724538509055159,'<code>gamma(.5)</code> should return <code>1.7724538509055159</code>.')
```
@ -53,16 +53,6 @@ function gamma (x) {
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution

View File

@ -20,19 +20,19 @@ Write a function to solve \(A.x = b\) using Gaussian elimination then backwards
```yml
tests:
- text: <code>gaussianElimination</code> should be a function.
testString: 'assert(typeof gaussianElimination=="function","<code>gaussianElimination</code> should be a function.");'
- text: <code>gaussianElimination("+JSON.stringify(tests[0][0])+","+JSON.stringify(tests[0][1])+")</code> should return an array.
testString: 'assert(Array.isArray(gaussianElimination(tests[0][0],tests[0][1])),"<code>gaussianElimination("+JSON.stringify(tests[0][0])+","+JSON.stringify(tests[0][1])+")</code> should return an array.");'
- text: <code>gaussianElimination("+JSON.stringify(tests[0][0])+","+JSON.stringify(tests[0][1])+")</code> should return <code>"+JSON.stringify(results[0])+"</code>.
testString: 'assert.deepEqual(gaussianElimination(tests[0][0],tests[0][1]),results[0],"<code>gaussianElimination("+JSON.stringify(tests[0][0])+","+JSON.stringify(tests[0][1])+")</code> should return <code>"+JSON.stringify(results[0])+"</code>.");'
- text: <code>gaussianElimination("+JSON.stringify(tests[1][0])+","+JSON.stringify(tests[1][1])+")</code> should return <code>"+JSON.stringify(results[1])+"</code>.
testString: 'assert.deepEqual(gaussianElimination(tests[1][0],tests[1][1]),results[1],"<code>gaussianElimination("+JSON.stringify(tests[1][0])+","+JSON.stringify(tests[1][1])+")</code> should return <code>"+JSON.stringify(results[1])+"</code>.");'
- text: <code>gaussianElimination("+JSON.stringify(tests[2][0])+","+JSON.stringify(tests[2][1])+")</code> should return <code>"+JSON.stringify(results[2])+"</code>.
testString: 'assert.deepEqual(gaussianElimination(tests[2][0],tests[2][1]),results[2],"<code>gaussianElimination("+JSON.stringify(tests[2][0])+","+JSON.stringify(tests[2][1])+")</code> should return <code>"+JSON.stringify(results[2])+"</code>.");'
- text: <code>gaussianElimination("+JSON.stringify(tests[3][0])+","+JSON.stringify(tests[3][1])+")</code> should return <code>"+JSON.stringify(results[3])+"</code>.
testString: 'assert.deepEqual(gaussianElimination(tests[3][0],tests[3][1]),results[3],"<code>gaussianElimination("+JSON.stringify(tests[3][0])+","+JSON.stringify(tests[3][1])+")</code> should return <code>"+JSON.stringify(results[3])+"</code>.");'
- text: <code>gaussianElimination("+JSON.stringify(tests[4][0])+","+JSON.stringify(tests[4][1])+")</code> should return <code>"+JSON.stringify(results[4])+"</code>.
testString: 'assert.deepEqual(gaussianElimination(tests[4][0],tests[4][1]),results[4],"<code>gaussianElimination("+JSON.stringify(tests[4][0])+","+JSON.stringify(tests[4][1])+")</code> should return <code>"+JSON.stringify(results[4])+"</code>.");'
testString: assert(typeof gaussianElimination=='function','<code>gaussianElimination</code> should be a function.');
- text: <code>gaussianElimination([[1,1],[1,-1]], [5,1])</code> should return an array.
testString: assert(Array.isArray(gaussianElimination([[1,1],[1,-1]], [5,1])),'<code>gaussianElimination([[1,1],[1,-1]], [5,1])</code> should return an array.');
- text: <code>gaussianElimination([[1,1],[1,-1]], [5,1])</code> should return <code>[ 3, 2 ]</code>.
testString: assert.deepEqual(gaussianElimination([[1,1],[1,-1]], [5,1]), [ 3, 2 ],'<code>gaussianElimination([[1,1],[1,-1]], [5,1])</code> should return <code>[ 3, 2 ]</code>.');
- text: <code>gaussianElimination([[2,3],[2,1]] , [8,4])</code> should return <code>[ 1, 2 ]</code>.
testString: assert.deepEqual(gaussianElimination([[2,3],[2,1]] , [8,4]), [ 1, 2 ],'<code>gaussianElimination([[2,3],[2,1]] , [8,4])</code> should return <code>[ 1, 2 ]</code>.');
- text: <code>gaussianElimination([[1,3],[5,-2]], [14,19])</code> should return <code>[ 5, 3 ]</code>.
testString: assert.deepEqual(gaussianElimination([[1,3],[5,-2]], [14,19]), [ 5, 3 ],'<code>gaussianElimination([[1,3],[5,-2]], [14,19])</code> should return <code>[ 5, 3 ]</code>.');
- text: <code>gaussianElimination([[1,1],[5,-1]] , [10,14])</code> should return <code>[ 4, 6 ]</code>.
testString: assert.deepEqual(gaussianElimination([[1,1],[5,-1]] , [10,14]), [ 4, 6 ],'<code>gaussianElimination([[1,1],[5,-1]] , [10,14])</code> should return <code>[ 4, 6 ]</code>.');
- text: <code>gaussianElimination([[1,2,3],[4,5,6],[7,8,8]] , [6,15,23])</code> should return <code>[ 1, 1, 1 ]</code>.
testString: assert.deepEqual(gaussianElimination([[1,2,3],[4,5,6],[7,8,8]] , [6,15,23]), [ 1, 1, 1 ],'<code>gaussianElimination([[1,2,3],[4,5,6],[7,8,8]] , [6,15,23])</code> should return <code>[ 1, 1, 1 ]</code>.');
```
@ -51,16 +51,6 @@ function gaussianElimination (A,b) {
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution

View File

@ -24,23 +24,23 @@ The second parameter is the number for which the function should return a string
```yml
tests:
- text: <code>genFizzBuzz</code> should be a function.
testString: 'assert(typeof genFizzBuzz=="function","<code>genFizzBuzz</code> should be a function.");'
- text: <code>genFizzBuzz("+JSON.stringify(tests[0][0])+","+tests[0][1]+")</code> should return a type.
testString: 'assert(typeof genFizzBuzz(tests[0][0],tests[0][1])=="string","<code>genFizzBuzz("+JSON.stringify(tests[0][0])+","+tests[0][1]+")</code> should return a type.");'
- text: <code>genFizzBuzz("+JSON.stringify(tests[0][0])+","+tests[0][1]+")</code> should return <code>""+results[0]+""</code>.
testString: 'assert.equal(genFizzBuzz(tests[0][0],tests[0][1]),results[0],"<code>genFizzBuzz("+JSON.stringify(tests[0][0])+","+tests[0][1]+")</code> should return <code>""+results[0]+""</code>.");'
- text: <code>genFizzBuzz("+JSON.stringify(tests[1][0])+","+tests[1][1]+")</code> should return <code>""+results[1]+""</code>.
testString: 'assert.equal(genFizzBuzz(tests[1][0],tests[1][1]),results[1],"<code>genFizzBuzz("+JSON.stringify(tests[1][0])+","+tests[1][1]+")</code> should return <code>""+results[1]+""</code>.");'
- text: <code>genFizzBuzz("+JSON.stringify(tests[2][0])+","+tests[2][1]+")</code> should return <code>""+results[2]+""</code>.
testString: 'assert.equal(genFizzBuzz(tests[2][0],tests[2][1]),results[2],"<code>genFizzBuzz("+JSON.stringify(tests[2][0])+","+tests[2][1]+")</code> should return <code>""+results[2]+""</code>.");'
- text: <code>genFizzBuzz("+JSON.stringify(tests[3][0])+","+tests[3][1]+")</code> should return <code>""+results[3]+""</code>.
testString: 'assert.equal(genFizzBuzz(tests[3][0],tests[3][1]),results[3],"<code>genFizzBuzz("+JSON.stringify(tests[3][0])+","+tests[3][1]+")</code> should return <code>""+results[3]+""</code>.");'
- text: <code>genFizzBuzz("+JSON.stringify(tests[4][0])+","+tests[4][1]+")</code> should return <code>""+results[4]+""</code>.
testString: 'assert.equal(genFizzBuzz(tests[4][0],tests[4][1]),results[4],"<code>genFizzBuzz("+JSON.stringify(tests[4][0])+","+tests[4][1]+")</code> should return <code>""+results[4]+""</code>.");'
- text: <code>genFizzBuzz("+JSON.stringify(tests[5][0])+","+tests[5][1]+")</code> should return <code>""+results[5]+""</code>.
testString: 'assert.equal(genFizzBuzz(tests[5][0],tests[5][1]),results[5],"<code>genFizzBuzz("+JSON.stringify(tests[5][0])+","+tests[5][1]+")</code> should return <code>""+results[5]+""</code>.");'
- text: <code>genFizzBuzz("+JSON.stringify(tests[6][0])+","+tests[6][1]+")</code> should return <code>""+results[6]+""</code>.
testString: 'assert.equal(genFizzBuzz(tests[6][0],tests[6][1]),results[6],"<code>genFizzBuzz("+JSON.stringify(tests[6][0])+","+tests[6][1]+")</code> should return <code>""+results[6]+""</code>.");'
testString: assert(typeof genFizzBuzz=='function','<code>genFizzBuzz</code> should be a function.');
- text: <code>genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 6)</code> should return a string.
testString: assert(typeof genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 6)=='string','<code>genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 6)</code> should return a string.');
- text: <code>genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 6)</code> should return <code>"Fizz"</code>.
testString: assert.equal(genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 6), "Fizz",'<code>genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 6)</code> should return <code>"Fizz"</code>.');
- text: <code>genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 10)</code> should return <code>"Buzz"</code>.
testString: assert.equal(genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 10), "Buzz",'<code>genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 10)</code> should return <code>"Buzz"</code>.');
- text: <code>genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 12)</code> should return <code>"Buzz"</code>.
testString: assert.equal(genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 12), "Buzz",'<code>genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 12)</code> should return <code>"Buzz"</code>.');
- text: <code>genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 13)</code> should return <code>"13"</code>.
testString: assert.equal(genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 13), '13','<code>genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 13)</code> should return <code>"13"</code>.');
- text: <code>genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 15)</code> should return <code>"BuzzFizz"</code>.
testString: assert.equal(genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 15), 'BuzzFizz','<code>genFizzBuzz([[3, "Buzz"],[5, "Fizz"]], 15)</code> should return <code>"BuzzFizz"</code>.');
- text: <code>genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 15)</code> should return <code>"FizzBuzz"</code>.
testString: assert.equal(genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 15), 'FizzBuzz','<code>genFizzBuzz([[3, "Fizz"],[5, "Buzz"]], 15)</code> should return <code>"FizzBuzz"</code>.');
- text: <code>genFizzBuzz([[3, "Fizz"],[5, "Buzz"],[7, "Baxx"]], 105)</code> should return <code>"FizzBuzzBaxx"</code>.
testString: assert.equal(genFizzBuzz([[3, "Fizz"],[5, "Buzz"],[7, "Baxx"]], 105), 'FizzBuzzBaxx','<code>genFizzBuzz([[3, "Fizz"],[5, "Buzz"],[7, "Baxx"]], 105)</code> should return <code>"FizzBuzzBaxx"</code>.');
```
@ -59,16 +59,6 @@ function genFizzBuzz (rules, num) {
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution
@ -77,13 +67,13 @@ console.info('after the test');
```js
function genFizzBuzz(rules, num) {
let res=";
let res='';
rules.forEach(function (e) {
if(num % e[0] == 0)
res+=e[1];
})
if(res=="){
if(res==''){
res=num.toString();
}

View File

@ -20,19 +20,19 @@ Write a function to generate an array of lower case ASCII characters, for a give
```yml
tests:
- text: <code>lascii</code> should be a function.
testString: 'assert(typeof lascii=="function","<code>lascii</code> should be a function.");'
testString: assert(typeof lascii=='function','<code>lascii</code> should be a function.');
- text: <code>lascii("a","d")</code> should return an array.
testString: 'assert(Array.isArray(lascii("a","d")),"<code>lascii("a","d")</code> should return an array.");'
- text: '"<code>lascii("a","d")</code> should return <code>[ "a", "b", "c", "d" ]</code>."'
testString: 'assert.deepEqual(lascii("a","d"),results[0],"<code>lascii("a","d")</code> should return <code>[ "a", "b", "c", "d" ]</code>.");'
- text: '"<code>lascii("c","i")</code> should return <code>[ "c", "d", "e", "f", "g", "h", "i" ]</code>."'
testString: 'assert.deepEqual(lascii("c","i"),results[1],"<code>lascii("c","i")</code> should return <code>[ "c", "d", "e", "f", "g", "h", "i" ]</code>.");'
- text: '"<code>lascii("m","q")</code> should return <code>[ "m", "n", "o", "p", "q" ]</code>."'
testString: 'assert.deepEqual(lascii("m","q"),results[2],"<code>lascii("m","q")</code> should return <code>[ "m", "n", "o", "p", "q" ]</code>.");'
- text: '"<code>lascii("k","n")</code> should return <code>[ "k", "l", "m", "n" ]</code>.")'
testString: 'assert.deepEqual(lascii("k","n"),results[3],"<code>lascii("k","n")</code> should return <code>[ "k", "l", "m", "n" ]</code>.");'
- text: '"<code>lascii("t","z")</code> should return <code>[ "t", "u", "v", "w", "x", "y", "z" ]</code>."'
testString: 'assert.deepEqual(lascii("t","z"),results[4],"<code>lascii("t","z")</code> should return <code>[ "t", "u", "v", "w", "x", "y", "z" ]</code>.");'
testString: assert(Array.isArray(lascii('a','d')),'<code>lascii("a","d")</code> should return an array.');
- text: "<code>lascii('a','d')</code> should return <code>[ 'a', 'b', 'c', 'd' ]</code>."
testString: assert.deepEqual(lascii("a","d"),results[0],"<code>lascii('a','d')</code> should return <code>[ 'a', 'b', 'c', 'd' ]</code>.");
- text: <code>lascii('c','i')</code> should return <code>[ 'c', 'd', 'e', 'f', 'g', 'h', 'i' ]</code>.
testString: assert.deepEqual(lascii("c","i"),results[1],"<code>lascii('c','i')</code> should return <code>[ 'c', 'd', 'e', 'f', 'g', 'h', 'i' ]</code>.");
- text: <code>lascii('m','q')</code> should return <code>[ 'm', 'n', 'o', 'p', 'q' ]</code>.
testString: assert.deepEqual(lascii("m","q"),results[2],"<code>lascii('m','q')</code> should return <code>[ 'm', 'n', 'o', 'p', 'q' ]</code>.");
- text: <code>lascii('k','n')</code> should return <code>[ 'k', 'l', 'm', 'n' ]</code>.
testString: assert.deepEqual(lascii("k","n"),results[3],"<code>lascii('k','n')</code> should return <code>[ 'k', 'l', 'm', 'n' ]</code>.");
- text: <code>lascii('t','z')</code> should return <code>[ 't', 'u', 'v', 'w', 'x', 'y', 'z' ]</code>.
testString: assert.deepEqual(lascii("t","z"),results[4],"<code>lascii('t','z')</code> should return <code>[ 't', 'u', 'v', 'w', 'x', 'y', 'z' ]</code>.");
```
@ -56,7 +56,13 @@ function lascii (cFrom, cTo) {
<div id='js-teardown'>
```js
console.info('after the test');
let results=[
[ 'a', 'b', 'c', 'd' ],
[ 'c', 'd', 'e', 'f', 'g', 'h', 'i' ],
[ 'm', 'n', 'o', 'p', 'q' ],
[ 'k', 'l', 'm', 'n' ],
[ 't', 'u', 'v', 'w', 'x', 'y', 'z' ]
]
```
</div>

View File

@ -25,19 +25,19 @@ For example for \(n=7\), the function should return 81 as the sequence would be
```yml
tests:
- text: <code>exponentialGenerator</code> should be a function.
testString: 'assert(typeof exponentialGenerator=="function","<code>exponentialGenerator</code> should be a function.");'
testString: assert(typeof exponentialGenerator=='function','<code>exponentialGenerator</code> should be a function.');
- text: <code>exponentialGenerator()</code> should return a number.
testString: 'assert(typeof exponentialGenerator(10)=="number","<code>exponentialGenerator()</code> should return a number.");'
testString: assert(typeof exponentialGenerator(10)=='number','<code>exponentialGenerator()</code> should return a number.');
- text: <code>exponentialGenerator(10)</code> should return <code>144</code>.
testString: 'assert.equal(exponentialGenerator(10),144,"<code>exponentialGenerator(10)</code> should return <code>144</code>.");'
testString: assert.equal(exponentialGenerator(10),144,'<code>exponentialGenerator(10)</code> should return <code>144</code>.');
- text: <code>exponentialGenerator(12)</code> should return <code>196</code>.
testString: 'assert.equal(exponentialGenerator(12),196,"<code>exponentialGenerator(12)</code> should return <code>196</code>.");'
testString: assert.equal(exponentialGenerator(12),196,'<code>exponentialGenerator(12)</code> should return <code>196</code>.');
- text: <code>exponentialGenerator(14)</code> should return <code>256</code>.
testString: 'assert.equal(exponentialGenerator(14),256,"<code>exponentialGenerator(14)</code> should return <code>256</code>.");'
testString: assert.equal(exponentialGenerator(14),256,'<code>exponentialGenerator(14)</code> should return <code>256</code>.');
- text: <code>exponentialGenerator(20)</code> should return <code>484</code>.
testString: 'assert.equal(exponentialGenerator(20),484,"<code>exponentialGenerator(20)</code> should return <code>484</code>.");'
testString: assert.equal(exponentialGenerator(20),484,'<code>exponentialGenerator(20)</code> should return <code>484</code>.');
- text: <code>exponentialGenerator(25)</code> should return <code>784</code>.
testString: 'assert.equal(exponentialGenerator(25),784,"<code>exponentialGenerator(25)</code> should return <code>784</code>.");'
testString: assert.equal(exponentialGenerator(25),784,'<code>exponentialGenerator(25)</code> should return <code>784</code>.');
```

View File

@ -29,21 +29,21 @@ There are many possible Gray codes. The following encodes what is called "binary
```yml
tests:
- text: <code>gray</code> should be a function.
testString: 'assert(typeof gray=="function","<code>gray</code> should be a function.");'
testString: assert(typeof gray=='function','<code>gray</code> should be a function.');
- text: <code>gray(true,177)</code> should return a number.
testString: 'assert(typeof gray(true,177)=="number","<code>gray(true,177)</code> should return a number.");'
testString: assert(typeof gray(true,177)=='number','<code>gray(true,177)</code> should return a number.');
- text: <code>gray(true,177)</code> should return <code>233</code>.
testString: 'assert.equal(gray(true,177),233,"<code>gray(true,177)</code> should return <code>233</code>.");'
testString: assert.equal(gray(true,177),233,'<code>gray(true,177)</code> should return <code>233</code>.');
- text: <code>gray(true,425)</code> should return <code>381</code>.
testString: 'assert.equal(gray(true,425),381,"<code>gray(true,425)</code> should return <code>381</code>.");'
testString: assert.equal(gray(true,425),381,'<code>gray(true,425)</code> should return <code>381</code>.');
- text: <code>gray(true,870)</code> should return <code>725</code>.
testString: 'assert.equal(gray(true,870),725,"<code>gray(true,870)</code> should return <code>725</code>.");'
testString: assert.equal(gray(true,870),725,'<code>gray(true,870)</code> should return <code>725</code>.');
- text: <code>gray(false,233)</code> should return <code>177</code>.
testString: 'assert.equal(gray(false,233),177,"<code>gray(false,233)</code> should return <code>177</code>.");'
testString: assert.equal(gray(false,233),177,'<code>gray(false,233)</code> should return <code>177</code>.');
- text: <code>gray(false,381)</code> should return <code>425</code>.
testString: 'assert.equal(gray(false,381),425,"<code>gray(false,381)</code> should return <code>425</code>.");'
testString: assert.equal(gray(false,381),425,'<code>gray(false,381)</code> should return <code>425</code>.');
- text: <code>gray(false,725)</code> should return <code>870</code>.
testString: 'assert.equal(gray(false,725),870,"<code>gray(false,725)</code> should return <code>870</code>.");'
testString: assert.equal(gray(false,725),870,'<code>gray(false,725)</code> should return <code>870</code>.');
```

View File

@ -20,21 +20,21 @@ Write a function that returns the greatest common divisor of two integers.
```yml
tests:
- text: <code>gcd</code> should be a function.
testString: 'assert(typeof gcd=="function","<code>gcd</code> should be a function.");'
testString: assert(typeof gcd=='function','<code>gcd</code> should be a function.');
- text: <code>gcd(24,36)</code> should return a number.
testString: 'assert(typeof gcd(24,36)=="number","<code>gcd(24,36)</code> should return a number.");'
testString: assert(typeof gcd(24,36)=='number','<code>gcd(24,36)</code> should return a number.');
- text: <code>gcd(24,36)</code> should return <code>12</code>.
testString: 'assert.equal(gcd(24,36),12,"<code>gcd(24,36)</code> should return <code>12</code>.");'
testString: assert.equal(gcd(24,36),12,'<code>gcd(24,36)</code> should return <code>12</code>.');
- text: <code>gcd(30,48)</code> should return <code>6</code>.
testString: 'assert.equal(gcd(30,48),6,"<code>gcd(30,48)</code> should return <code>6</code>.");'
testString: assert.equal(gcd(30,48),6,'<code>gcd(30,48)</code> should return <code>6</code>.');
- text: <code>gcd(10,15)</code> should return <code>5</code>.
testString: 'assert.equal(gcd(10,15),5,"<code>gcd(10,15)</code> should return <code>5</code>.");'
testString: assert.equal(gcd(10,15),5,'<code>gcd(10,15)</code> should return <code>5</code>.');
- text: <code>gcd(100,25)</code> should return <code>25</code>.
testString: 'assert.equal(gcd(100,25),25,"<code>gcd(100,25)</code> should return <code>25</code>.");'
testString: assert.equal(gcd(100,25),25,'<code>gcd(100,25)</code> should return <code>25</code>.');
- text: <code>gcd(13,250)</code> should return <code>1</code>.
testString: 'assert.equal(gcd(13,250),1,"<code>gcd(13,250)</code> should return <code>1</code>.");'
testString: assert.equal(gcd(13,250),1,'<code>gcd(13,250)</code> should return <code>1</code>.');
- text: <code>gcd(1300,250)</code> should return <code>50</code>.
testString: 'assert.equal(gcd(1300,250),50,"<code>gcd(1300,250)</code> should return <code>50</code>.");'
testString: assert.equal(gcd(1300,250),50,'<code>gcd(1300,250)</code> should return <code>50</code>.');
```

View File

@ -21,21 +21,21 @@ An empty subsequence is considered to have the sum of \( 0 \); thus if all elem
```yml
tests:
- text: <code>maximumSubsequence</code> should be a function.
testString: 'assert(typeof maximumSubsequence=="function","<code>maximumSubsequence</code> should be a function.");'
- text: <code>maximumSubsequence("+JSON.stringify(tests[0])+")</code> should return an array.
testString: 'assert(Array.isArray(maximumSubsequence(tests[0])),"<code>maximumSubsequence("+JSON.stringify(tests[0])+")</code> should return an array.");'
- text: <code>maximumSubsequence("+JSON.stringify(tests[0])+")</code> should return <code>"+JSON.stringify(results[0])+"</code>.
testString: 'assert.deepEqual(maximumSubsequence(tests[0]),results[0],"<code>maximumSubsequence("+JSON.stringify(tests[0])+")</code> should return <code>"+JSON.stringify(results[0])+"</code>.");'
- text: <code>maximumSubsequence("+JSON.stringify(tests[1])+")</code> should return <code>"+JSON.stringify(results[1])+"</code>.
testString: 'assert.deepEqual(maximumSubsequence(tests[1]),results[1],"<code>maximumSubsequence("+JSON.stringify(tests[1])+")</code> should return <code>"+JSON.stringify(results[1])+"</code>.");'
- text: <code>maximumSubsequence("+JSON.stringify(tests[2])+")</code> should return <code>"+JSON.stringify(results[2])+"</code>.
testString: 'assert.deepEqual(maximumSubsequence(tests[2]),results[2],"<code>maximumSubsequence("+JSON.stringify(tests[2])+")</code> should return <code>"+JSON.stringify(results[2])+"</code>.");'
- text: <code>maximumSubsequence("+JSON.stringify(tests[3])+")</code> should return <code>"+JSON.stringify(results[3])+"</code>.
testString: 'assert.deepEqual(maximumSubsequence(tests[3]),results[3],"<code>maximumSubsequence("+JSON.stringify(tests[3])+")</code> should return <code>"+JSON.stringify(results[3])+"</code>.");'
- text: <code>maximumSubsequence("+JSON.stringify(tests[4])+")</code> should return <code>"+JSON.stringify(results[4])+"</code>.
testString: 'assert.deepEqual(maximumSubsequence(tests[4]),results[4],"<code>maximumSubsequence("+JSON.stringify(tests[4])+")</code> should return <code>"+JSON.stringify(results[4])+"</code>.");'
- text: <code>maximumSubsequence("+JSON.stringify(tests[5])+")</code> should return <code>"+JSON.stringify(results[5])+"</code>.
testString: 'assert.deepEqual(maximumSubsequence(tests[5]),results[5],"<code>maximumSubsequence("+JSON.stringify(tests[5])+")</code> should return <code>"+JSON.stringify(results[5])+"</code>.");'
testString: assert(typeof maximumSubsequence=='function','<code>maximumSubsequence</code> should be a function.');
- text: <code>maximumSubsequence([1,2,-1,3,10,-10])</code> should return an array.
testString: assert(Array.isArray(maximumSubsequence([1,2,-1,3,10,-10])),'<code>maximumSubsequence([1,2,-1,3,10,-10])</code> should return an array.');
- text: <code>maximumSubsequence([1,2,-1,3,10,-10])</code> should return <code>[ 1, 2, -1, 3, 10 ]</code>.
testString: assert.deepEqual(maximumSubsequence([1,2,-1,3,10,-10]), [ 1, 2, -1, 3, 10 ],'<code>maximumSubsequence([1,2,-1,3,10,-10])</code> should return <code>[ 1, 2, -1, 3, 10 ]</code>.');
- text: <code>maximumSubsequence([0, 8, 10, -2, -4, -1, -5, -3])</code> should return <code>[ 0, 8, 10 ]</code>.
testString: assert.deepEqual(maximumSubsequence([0, 8, 10, -2, -4, -1, -5, -3]), [ 0, 8, 10 ],'<code>maximumSubsequence([0, 8, 10, -2, -4, -1, -5, -3])</code> should return <code>[ 0, 8, 10 ]</code>.');
- text: <code>maximumSubsequence([9, 9, -10, 1])</code> should return <code>[ 9, 9 ]</code>.
testString: assert.deepEqual(maximumSubsequence([9, 9, -10, 1]), [ 9, 9 ],'<code>maximumSubsequence([9, 9, -10, 1])</code> should return <code>[ 9, 9 ]</code>.');
- text: <code>maximumSubsequence([7, 1, -5, -3, -8, 1]</code> should return <code>[ 7, 1 ]</code>.
testString: assert.deepEqual(maximumSubsequence([7, 1, -5, -3, -8, 1]), [ 7, 1 ],'<code>maximumSubsequence([7, 1, -5, -3, -8, 1]</code> should return <code>[ 7, 1 ]</code>.');
- text: <code>maximumSubsequence([-3, 6, -1, 4, -4, -6])</code> should return <code>[ 6, -1, 4 ]</code>.
testString: assert.deepEqual(maximumSubsequence([-3, 6, -1, 4, -4, -6]), [ 6, -1, 4 ],'<code>maximumSubsequence([-3, 6, -1, 4, -4, -6])</code> should return <code>[ 6, -1, 4 ]</code>.');
- text: <code>maximumSubsequence([-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1])</code> should return <code>[ 3, 5, 6, -2, -1, 4 ]</code>.
testString: assert.deepEqual(maximumSubsequence([-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1]), [ 3, 5, 6, -2, -1, 4 ],'<code>maximumSubsequence([-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1])</code> should return <code>[ 3, 5, 6, -2, -1, 4 ]</code>.');
```
@ -54,16 +54,6 @@ function maximumSubsequence (population) {
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution

View File

@ -29,9 +29,9 @@ Show the number less than 100,000 which has the longest hailstone sequence toget
```yml
tests:
- text: <code>hailstoneSequence</code> is a function.
testString: 'assert(typeof hailstoneSequence === "function", "<code>hailstoneSequence</code> is a function.");'
- text: '<code>hailstoneSequence()</code> should return <code>[[27,82,41,124,8,4,2,1], [351, 77031]]</code>'
testString: 'assert.deepEqual(hailstoneSequence(), res, "<code>hailstoneSequence()</code> should return <code>[[27,82,41,124,8,4,2,1], [351, 77031]]</code>");'
testString: assert(typeof hailstoneSequence === 'function', '<code>hailstoneSequence</code> is a function.');
- text: <code>hailstoneSequence()</code> should return <code>[[27,82,41,124,8,4,2,1], [351, 77031]]</code>
testString: assert.deepEqual(hailstoneSequence(), res, '<code>hailstoneSequence()</code> should return <code>[[27,82,41,124,8,4,2,1], [351, 77031]]</code>');
```
@ -59,7 +59,7 @@ function hailstoneSequence () {
<div id='js-teardown'>
```js
console.info('after the test');
const res = [[27, 82, 41, 124, 8, 4, 2, 1], [351, 77031]];
```
</div>

View File

@ -22,31 +22,31 @@ challengeType: 5
```yml
tests:
- text: <code>happy</code> is a function.
testString: 'assert(typeof happy === "function", "<code>happy</code> is a function.");'
testString: assert(typeof happy === 'function', '<code>happy</code> is a function.');
- text: <code>happy(1)</code> should return a boolean.
testString: 'assert(typeof happy(1) === "boolean", "<code>happy(1)</code> should return a boolean.");'
testString: assert(typeof happy(1) === 'boolean', '<code>happy(1)</code> should return a boolean.');
- text: <code>happy(1)</code> should return true.
testString: 'assert(happy(1), "<code>happy(1)</code> should return true.");'
testString: assert(happy(1), '<code>happy(1)</code> should return true.');
- text: <code>happy(2)</code> should return false.
testString: 'assert(!happy(2), "<code>happy(2)</code> should return false.");'
testString: assert(!happy(2), '<code>happy(2)</code> should return false.');
- text: <code>happy(7)</code> should return true.
testString: 'assert(happy(7), "<code>happy(7)</code> should return true.");'
testString: assert(happy(7), '<code>happy(7)</code> should return true.');
- text: <code>happy(10)</code> should return true.
testString: 'assert(happy(10), "<code>happy(10)</code> should return true.");'
testString: assert(happy(10), '<code>happy(10)</code> should return true.');
- text: <code>happy(13)</code> should return true.
testString: 'assert(happy(13), "<code>happy(13)</code> should return true.");'
testString: assert(happy(13), '<code>happy(13)</code> should return true.');
- text: <code>happy(19)</code> should return true.
testString: 'assert(happy(19), "<code>happy(19)</code> should return true.");'
testString: assert(happy(19), '<code>happy(19)</code> should return true.');
- text: <code>happy(23)</code> should return true.
testString: 'assert(happy(23), "<code>happy(23)</code> should return true.");'
testString: assert(happy(23), '<code>happy(23)</code> should return true.');
- text: <code>happy(28)</code> should return true.
testString: 'assert(happy(28), "<code>happy(28)</code> should return true.");'
testString: assert(happy(28), '<code>happy(28)</code> should return true.');
- text: <code>happy(31)</code> should return true.
testString: 'assert(happy(31), "<code>happy(31)</code> should return true.");'
- text: '<code>happy(32)</code> should return true:.'
testString: 'assert(happy(32), "<code>happy(32)</code> should return true:.");'
testString: assert(happy(31), '<code>happy(31)</code> should return true.');
- text: <code>happy(32)</code> should return true:.
testString: assert(happy(32), '<code>happy(32)</code> should return true:.');
- text: <code>happy(33)</code> should return false.
testString: 'assert(!happy(33), "<code>happy(33)</code> should return false.");'
testString: assert(!happy(33), '<code>happy(33)</code> should return false.');
```

View File

@ -23,9 +23,9 @@ Task:
```yml
tests:
- text: <code>isHarshadOrNiven</code> is a function.
testString: 'assert(typeof isHarshadOrNiven === "function", "<code>isHarshadOrNiven</code> is a function.");'
testString: assert(typeof isHarshadOrNiven === 'function', '<code>isHarshadOrNiven</code> is a function.');
- text: '<code>isHarshadOrNiven()</code> should return <code>{"firstTwenty": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42],"firstOver1000": 1002}</code>'
testString: 'assert.deepEqual(isHarshadOrNiven(), res, "<code>isHarshadOrNiven()</code> should return <code>{"firstTwenty": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42],"firstOver1000": 1002}</code>");'
testString: 'assert.deepEqual(isHarshadOrNiven(), res, ''<code>isHarshadOrNiven()</code> should return <code>{"firstTwenty": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42],"firstOver1000": 1002}</code>'');'
```
@ -55,7 +55,10 @@ function isHarshadOrNiven () {
<div id='js-teardown'>
```js
console.info('after the test');
const res = {
firstTwenty: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42],
firstOver1000: 1002
};
```
</div>

View File

@ -23,19 +23,19 @@ Related task:
```yml
tests:
- text: <code>arrToObj</code> is a function.
testString: 'assert(typeof arrToObj === "function", "<code>arrToObj</code> is a function.");'
testString: assert(typeof arrToObj === 'function', '<code>arrToObj</code> is a function.');
- text: '<code>arrToObj([1, 2, 3, 4, 5], ["a", "b", "c", "d", "e"])</code> should return <code>{ 1: "a", 2: "b", 3: "c", 4: "d", 5: "e" }</code>'
testString: 'assert.deepEqual(arrToObj(...testCases[0]), res[0], "<code>arrToObj([1, 2, 3, 4, 5], ["a", "b", "c", "d", "e"])</code> should return <code>{ 1: "a", 2: "b", 3: "c", 4: "d", 5: "e" }</code>");'
testString: 'assert.deepEqual(arrToObj(...testCases[0]), res[0], ''<code>arrToObj([1, 2, 3, 4, 5], ["a", "b", "c", "d", "e"])</code> should return <code>{ 1: "a", 2: "b", 3: "c", 4: "d", 5: "e" }</code>'');'
- text: '<code>arrToObj([1, 2, 3, 4, 5], ["a", "b", "c", "d"])</code> should return <code>{ 1: "a", 2: "b", 3: "c", 4: "d", 5: undefined }</code>'
testString: 'assert.deepEqual(arrToObj(...testCases[1]), res[1], "<code>arrToObj([1, 2, 3, 4, 5], ["a", "b", "c", "d"])</code> should return <code>{ 1: "a", 2: "b", 3: "c", 4: "d", 5: undefined }</code>");'
testString: 'assert.deepEqual(arrToObj(...testCases[1]), res[1], ''<code>arrToObj([1, 2, 3, 4, 5], ["a", "b", "c", "d"])</code> should return <code>{ 1: "a", 2: "b", 3: "c", 4: "d", 5: undefined }</code>'');'
- text: '<code>arrToObj([1, 2, 3], ["a", "b", "c", "d", "e"])</code> should return <code>{ 1: "a", 2: "b", 3: "c" }</code>'
testString: 'assert.deepEqual(arrToObj(...testCases[2]), res[2], "<code>arrToObj([1, 2, 3], ["a", "b", "c", "d", "e"])</code> should return <code>{ 1: "a", 2: "b", 3: "c" }</code>");'
testString: 'assert.deepEqual(arrToObj(...testCases[2]), res[2], ''<code>arrToObj([1, 2, 3], ["a", "b", "c", "d", "e"])</code> should return <code>{ 1: "a", 2: "b", 3: "c" }</code>'');'
- text: '<code>arrToObj(["a", "b", "c", "d", "e"], [1, 2, 3, 4, 5])</code> should return <code>{ "a": 1, "b": 2, "c": 3 , "d": 4, "e": 5 }</code>'
testString: 'assert.deepEqual(arrToObj(...testCases[3]), res[3], "<code>arrToObj(["a", "b", "c", "d", "e"], [1, 2, 3, 4, 5])</code> should return <code>{ "a": 1, "b": 2, "c": 3 , "d": 4, "e": 5 }</code>");'
testString: 'assert.deepEqual(arrToObj(...testCases[3]), res[3], ''<code>arrToObj(["a", "b", "c", "d", "e"], [1, 2, 3, 4, 5])</code> should return <code>{ "a": 1, "b": 2, "c": 3 , "d": 4, "e": 5 }</code>'');'
- text: '<code>arrToObj(["a", "b", "c", "d", "e"], [1, 2, 3, 4])</code> should return <code>{ "a": 1, "b": 2, "c": 3 , "d": 4, "e": undefined }</code>'
testString: 'assert.deepEqual(arrToObj(...testCases[4]), res[4], "<code>arrToObj(["a", "b", "c", "d", "e"], [1, 2, 3, 4])</code> should return <code>{ "a": 1, "b": 2, "c": 3 , "d": 4, "e": undefined }</code>");'
testString: 'assert.deepEqual(arrToObj(...testCases[4]), res[4], ''<code>arrToObj(["a", "b", "c", "d", "e"], [1, 2, 3, 4])</code> should return <code>{ "a": 1, "b": 2, "c": 3 , "d": 4, "e": undefined }</code>'');'
- text: '<code>arrToObj(["a", "b", "c"], [1, 2, 3, 4, 5])</code> should return <code>{ "a": 1, "b": 2, "c": 3 }</code>'
testString: 'assert.deepEqual(arrToObj(...testCases[5]), res[5], "<code>arrToObj(["a", "b", "c"], [1, 2, 3, 4, 5])</code> should return <code>{ "a": 1, "b": 2, "c": 3 }</code>");'
testString: 'assert.deepEqual(arrToObj(...testCases[5]), res[5], ''<code>arrToObj(["a", "b", "c"], [1, 2, 3, 4, 5])</code> should return <code>{ "a": 1, "b": 2, "c": 3 }</code>'');'
```
@ -60,7 +60,23 @@ function arrToObj (keys, vals) {
<div id='js-teardown'>
```js
console.info('after the test');
const testCases = [
[[1, 2, 3, 4, 5], ['a', 'b', 'c', 'd', 'e']],
[[1, 2, 3, 4, 5], ['a', 'b', 'c', 'd']],
[[1, 2, 3], ['a', 'b', 'c', 'd', 'e']],
[['a', 'b', 'c', 'd', 'e'], [1, 2, 3, 4, 5]],
[['a', 'b', 'c', 'd', 'e'], [1, 2, 3, 4]],
[['a', 'b', 'c'], [1, 2, 3, 4, 5]]
];
const res = [
{ 1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: 'e' },
{ 1: 'a', 2: 'b', 3: 'c', 4: 'd', 5: undefined },
{ 1: 'a', 2: 'b', 3: 'c' },
{ a: 1, b: 2, c: 3, d: 4, e: 5 },
{ a: 1, b: 2, c: 3, d: 4, e: undefined },
{ a: 1, b: 2, c: 3 }
];
```
</div>

View File

@ -172,9 +172,9 @@ Test-case
```yml
tests:
- text: <code>hashJoin</code> is a function.
testString: 'assert(typeof hashJoin === "function", "<code>hashJoin</code> is a function.");'
testString: assert(typeof hashJoin === 'function', '<code>hashJoin</code> is a function.');
- text: '<code>hashJoin([{ age: 27, name: "Jonah" }, { age: 18, name: "Alan" }, { age: 28, name: "Glory" }, { age: 18, name: "Popeye" }, { age: 28, name: "Alan" }], [{ character: "Jonah", nemesis: "Whales" }, { character: "Jonah", nemesis: "Spiders" }, { character: "Alan", nemesis: "Ghosts" }, { character:"Alan", nemesis: "Zombies" }, { character: "Glory", nemesis: "Buffy" }, { character: "Bob", nemesis: "foo" }])</code> should return <code>[{"A_age": 27,"A_name": "Jonah", "B_character": "Jonah", "B_nemesis": "Whales"}, {"A_age": 27,"A_name": "Jonah", "B_character": "Jonah", "B_nemesis": "Spiders"}, {"A_age": 18,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Ghosts"}, {"A_age": 18,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Zombies"}, {"A_age": 28,"A_name": "Glory", "B_character": "Glory", "B_nemesis": "Buffy"}, {"A_age": 28,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Ghosts"}, {"A_age": 28,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Zombies"}]</code>'
testString: 'assert.deepEqual(hashJoin(hash1, hash2), res, "<code>hashJoin([{ age: 27, name: "Jonah" }, { age: 18, name: "Alan" }, { age: 28, name: "Glory" }, { age: 18, name: "Popeye" }, { age: 28, name: "Alan" }], [{ character: "Jonah", nemesis: "Whales" }, { character: "Jonah", nemesis: "Spiders" }, { character: "Alan", nemesis: "Ghosts" }, { character:"Alan", nemesis: "Zombies" }, { character: "Glory", nemesis: "Buffy" }, { character: "Bob", nemesis: "foo" }])</code> should return <code>[{"A_age": 27,"A_name": "Jonah", "B_character": "Jonah", "B_nemesis": "Whales"}, {"A_age": 27,"A_name": "Jonah", "B_character": "Jonah", "B_nemesis": "Spiders"}, {"A_age": 18,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Ghosts"}, {"A_age": 18,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Zombies"}, {"A_age": 28,"A_name": "Glory", "B_character": "Glory", "B_nemesis": "Buffy"}, {"A_age": 28,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Ghosts"}, {"A_age": 28,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Zombies"}]</code>");'
testString: 'assert.deepEqual(hashJoin(hash1, hash2), res, ''<code>hashJoin([{ age: 27, name: "Jonah" }, { age: 18, name: "Alan" }, { age: 28, name: "Glory" }, { age: 18, name: "Popeye" }, { age: 28, name: "Alan" }], [{ character: "Jonah", nemesis: "Whales" }, { character: "Jonah", nemesis: "Spiders" }, { character: "Alan", nemesis: "Ghosts" }, { character:"Alan", nemesis: "Zombies" }, { character: "Glory", nemesis: "Buffy" }, { character: "Bob", nemesis: "foo" }])</code> should return <code>[{"A_age": 27,"A_name": "Jonah", "B_character": "Jonah", "B_nemesis": "Whales"}, {"A_age": 27,"A_name": "Jonah", "B_character": "Jonah", "B_nemesis": "Spiders"}, {"A_age": 18,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Ghosts"}, {"A_age": 18,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Zombies"}, {"A_age": 28,"A_name": "Glory", "B_character": "Glory", "B_nemesis": "Buffy"}, {"A_age": 28,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Ghosts"}, {"A_age": 28,"A_name": "Alan", "B_character": "Alan", "B_nemesis": "Zombies"}]</code>'');'
```
@ -199,7 +199,35 @@ function hashJoin (hash1, hash2) {
<div id='js-teardown'>
```js
console.info('after the test');
const hash1 = [
{ age: 27, name: 'Jonah' },
{ age: 18, name: 'Alan' },
{ age: 28, name: 'Glory' },
{ age: 18, name: 'Popeye' },
{ age: 28, name: 'Alan' }
];
const hash2 = [
{ character: 'Jonah', nemesis: 'Whales' },
{ character: 'Jonah', nemesis: 'Spiders' },
{ character: 'Alan', nemesis: 'Ghosts' },
{ character: 'Alan', nemesis: 'Zombies' },
{ character: 'Glory', nemesis: 'Buffy' },
{ character: 'Bob', nemesis: 'foo' }
];
const res = [
{ A_age: 27, A_name: 'Jonah', B_character: 'Jonah', B_nemesis: 'Whales' },
{ A_age: 27, A_name: 'Jonah', B_character: 'Jonah', B_nemesis: 'Spiders' },
{ A_age: 18, A_name: 'Alan', B_character: 'Alan', B_nemesis: 'Ghosts' },
{ A_age: 18, A_name: 'Alan', B_character: 'Alan', B_nemesis: 'Zombies' },
{ A_age: 28, A_name: 'Glory', B_character: 'Glory', B_nemesis: 'Buffy' },
{ A_age: 28, A_name: 'Alan', B_character: 'Alan', B_nemesis: 'Ghosts' },
{ A_age: 28, A_name: 'Alan', B_character: 'Alan', B_nemesis: 'Zombies' }
];
const bench1 = [{ name: 'u2v7v', num: 1 }, { name: 'n53c8', num: 10 }, { name: 'oysce', num: 9 }, { name: '0mto2s', num: 1 }, { name: 'vkh5id', num: 4 }, { name: '5od0cf', num: 8 }, { name: 'uuulue', num: 10 }, { name: '3rgsbi', num: 9 }, { name: 'kccv35r', num: 4 }, { name: '80un74', num: 9 }, { name: 'h4pp3', num: 6 }, { name: '51bit', num: 7 }, { name: 'j9ndf', num: 8 }, { name: 'vf3u1', num: 10 }, { name: 'g0bw0om', num: 10 }, { name: 'j031x', num: 7 }, { name: 'ij3asc', num: 9 }, { name: 'byv83y', num: 8 }, { name: 'bjzp4k', num: 4 }, { name: 'f3kbnm', num: 10 }];
const bench2 = [{ friend: 'o8b', num: 8 }, { friend: 'ye', num: 2 }, { friend: '32i', num: 5 }, { friend: 'uz', num: 3 }, { friend: 'a5k', num: 4 }, { friend: 'uad', num: 7 }, { friend: '3w5', num: 10 }, { friend: 'vw', num: 10 }, { friend: 'ah', num: 4 }, { friend: 'qv', num: 7 }, { friend: 'ozv', num: 2 }, { friend: '9ri', num: 10 }, { friend: '7nu', num: 4 }, { friend: 'w3', num: 9 }, { friend: 'tgp', num: 8 }, { friend: 'ibs', num: 1 }, { friend: 'ss7', num: 6 }, { friend: 'g44', num: 9 }, { friend: 'tab', num: 9 }, { friend: 'zem', num: 10 }];
```
</div>

View File

@ -26,15 +26,15 @@ Task:
```yml
tests:
- text: <code>heronianTriangle</code> is a function.
testString: 'assert(typeof heronianTriangle === "function", "<code>heronianTriangle</code> is a function.");'
- text: '<code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17]]</code>'
testString: 'assert.deepEqual(heronianTriangle(testCases[0]), res[0], "<code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17]]</code>");'
- text: '<code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15]],</code>'
testString: 'assert.deepEqual(heronianTriangle(testCases[1]), res[1], "<code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15]],</code>");'
- text: '<code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53]],</code>'
testString: 'assert.deepEqual(heronianTriangle(testCases[2]), res[2], "<code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53]],</code>");'
- text: '<code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53], [19, 20, 37],[16, 17, 17], [17, 17, 30], [16, 25, 39], [13, 20, 21]]</code>'
testString: 'assert.deepEqual(heronianTriangle(testCases[3]), res[3], "<code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53], [19, 20, 37],[16, 17, 17], [17, 17, 30], [16, 25, 39], [13, 20, 21]]</code>");'
testString: assert(typeof heronianTriangle === 'function', '<code>heronianTriangle</code> is a function.');
- text: <code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17]]</code>
testString: assert.deepEqual(heronianTriangle(testCases[0]), res[0], '<code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17]]</code>');
- text: <code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15]],</code>
testString: assert.deepEqual(heronianTriangle(testCases[1]), res[1], '<code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15]],</code>');
- text: <code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53]],</code>
testString: assert.deepEqual(heronianTriangle(testCases[2]), res[2], '<code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53]],</code>');
- text: <code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53], [19, 20, 37],[16, 17, 17], [17, 17, 30], [16, 25, 39], [13, 20, 21]]</code>
testString: assert.deepEqual(heronianTriangle(testCases[3]), res[3], '<code>heronianTriangle()</code> should return <code>[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53], [19, 20, 37],[16, 17, 17], [17, 17, 30], [16, 25, 39], [13, 20, 21]]</code>');
```
@ -61,7 +61,14 @@ function heronianTriangle (n) {
<div id='js-teardown'>
```js
console.info('after the test');
const testCases = [10, 15, 20, 25];
const res = [
[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17]],
[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15]],
[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53]],
[[3, 4, 5], [5, 5, 6], [5, 5, 8], [4, 13, 15], [5, 12, 13], [9, 10, 17], [3, 25, 26], [7, 15, 20], [10, 13, 13], [8, 15, 17], [13, 13, 24], [6, 25, 29], [11, 13, 20], [5, 29, 30], [13, 14, 15], [10, 17, 21], [7, 24, 25], [8, 29, 35], [12, 17, 25], [4, 51, 53], [19, 20, 37], [16, 17, 17], [17, 17, 30], [16, 25, 39], [13, 20, 21]]
];
```
</div>

View File

@ -31,29 +31,29 @@ Wikipedia: <a href="https://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter
```yml
tests:
- text: <code>ffr</code> is a function.
testString: 'assert(typeof ffr === "function", "<code>ffr</code> is a function.");'
testString: assert(typeof ffr === 'function', '<code>ffr</code> is a function.');
- text: <code>ffs</code> is a function.
testString: 'assert(typeof ffs === "function", "<code>ffs</code> is a function.");'
testString: assert(typeof ffs === 'function', '<code>ffs</code> is a function.');
- text: <code>ffr</code> should return integer.
testString: 'assert(Number.isInteger(ffr(1)), "<code>ffr</code> should return integer.");'
testString: assert(Number.isInteger(ffr(1)), '<code>ffr</code> should return integer.');
- text: <code>ffs</code> should return integer.
testString: 'assert(Number.isInteger(ffs(1)), "<code>ffs</code> should return integer.");'
testString: assert(Number.isInteger(ffs(1)), '<code>ffs</code> should return integer.');
- text: <code>ffr()</code> should return <code>69</code>
testString: 'assert.equal(ffr(ffrParamRes[0][0]), ffrParamRes[0][1], "<code>ffr()</code> should return <code>69</code>");'
testString: assert.equal(ffr(ffrParamRes[0][0]), ffrParamRes[0][1], '<code>ffr()</code> should return <code>69</code>');
- text: <code>ffr()</code> should return <code>1509</code>
testString: 'assert.equal(ffr(ffrParamRes[1][0]), ffrParamRes[1][1], "<code>ffr()</code> should return <code>1509</code>");'
testString: assert.equal(ffr(ffrParamRes[1][0]), ffrParamRes[1][1], '<code>ffr()</code> should return <code>1509</code>');
- text: <code>ffr()</code> should return <code>5764</code>
testString: 'assert.equal(ffr(ffrParamRes[2][0]), ffrParamRes[2][1], "<code>ffr()</code> should return <code>5764</code>");'
testString: assert.equal(ffr(ffrParamRes[2][0]), ffrParamRes[2][1], '<code>ffr()</code> should return <code>5764</code>');
- text: <code>ffr()</code> should return <code>526334</code>
testString: 'assert.equal(ffr(ffrParamRes[3][0]), ffrParamRes[3][1], "<code>ffr()</code> should return <code>526334</code>");'
testString: assert.equal(ffr(ffrParamRes[3][0]), ffrParamRes[3][1], '<code>ffr()</code> should return <code>526334</code>');
- text: <code>ffs()</code> should return <code>14</code>
testString: 'assert.equal(ffs(ffsParamRes[0][0]), ffsParamRes[0][1], "<code>ffs()</code> should return <code>14</code>");'
testString: assert.equal(ffs(ffsParamRes[0][0]), ffsParamRes[0][1], '<code>ffs()</code> should return <code>14</code>');
- text: <code>ffs()</code> should return <code>59</code>
testString: 'assert.equal(ffs(ffsParamRes[1][0]), ffsParamRes[1][1], "<code>ffs()</code> should return <code>59</code>");'
testString: assert.equal(ffs(ffsParamRes[1][0]), ffsParamRes[1][1], '<code>ffs()</code> should return <code>59</code>');
- text: <code>ffs()</code> should return <code>112</code>
testString: 'assert.equal(ffs(ffsParamRes[2][0]), ffsParamRes[2][1], "<code>ffs()</code> should return <code>112</code>");'
testString: assert.equal(ffs(ffsParamRes[2][0]), ffsParamRes[2][1], '<code>ffs()</code> should return <code>112</code>');
- text: <code>ffs()</code> should return <code>1041</code>
testString: 'assert.equal(ffs(ffsParamRes[3][0]), ffsParamRes[3][1], "<code>ffs()</code> should return <code>1041</code>");'
testString: assert.equal(ffs(ffsParamRes[3][0]), ffsParamRes[3][1], '<code>ffs()</code> should return <code>1041</code>');
```
@ -82,7 +82,9 @@ function ffs(n) {
<div id='js-teardown'>
```js
console.info('after the test');
const ffrParamRes = [[10, 69], [50, 1509], [100, 5764], [1000, 526334]];
const ffsParamRes = [[10, 14], [50, 59], [100, 112], [1000, 1041]];
```
</div>

View File

@ -24,17 +24,17 @@ Implement the Hofstadter Q Sequence equation into JavaScript
```yml
tests:
- text: <code>hofstadterQ</code> is a function.
testString: 'assert(typeof hofstadterQ === "function", "<code>hofstadterQ</code> is a function.");'
testString: assert(typeof hofstadterQ === 'function', '<code>hofstadterQ</code> is a function.');
- text: <code>hofstadterQ()</code> should return <code>integer</code>
testString: 'assert(Number.isInteger(hofstadterQ(1000)), "<code>hofstadterQ()</code> should return <code>integer</code>");'
testString: assert(Number.isInteger(hofstadterQ(1000)), '<code>hofstadterQ()</code> should return <code>integer</code>');
- text: <code>hofstadterQ(1000)</code> should return <code>502</code>
testString: 'assert.equal(hofstadterQ(testCase[0]), res[0], "<code>hofstadterQ(1000)</code> should return <code>502</code>");'
testString: assert.equal(hofstadterQ(testCase[0]), res[0], '<code>hofstadterQ(1000)</code> should return <code>502</code>');
- text: <code>hofstadterQ(1500)</code> should return <code>755</code>
testString: 'assert.equal(hofstadterQ(testCase[1]), res[1], "<code>hofstadterQ(1500)</code> should return <code>755</code>");'
testString: assert.equal(hofstadterQ(testCase[1]), res[1], '<code>hofstadterQ(1500)</code> should return <code>755</code>');
- text: <code>hofstadterQ(2000)</code> should return <code>1005</code>
testString: 'assert.equal(hofstadterQ(testCase[2]), res[2], "<code>hofstadterQ(2000)</code> should return <code>1005</code>");'
testString: assert.equal(hofstadterQ(testCase[2]), res[2], '<code>hofstadterQ(2000)</code> should return <code>1005</code>');
- text: <code>hofstadterQ(2500)</code> should return <code>1261</code>
testString: 'assert.equal(hofstadterQ(testCase[3]), res[3], "<code>hofstadterQ(2500)</code> should return <code>1261</code>");'
testString: assert.equal(hofstadterQ(testCase[3]), res[3], '<code>hofstadterQ(2500)</code> should return <code>1261</code>');
```
@ -59,7 +59,8 @@ function hofstadterQ (n) {
<div id='js-teardown'>
```js
console.info('after the test');
const testCase = [1000, 1500, 2000, 2500];
const res = [502, 755, 1005, 1261];
```
</div>

View File

@ -24,21 +24,21 @@ Write a function that accepts a word and check if the word follows this rule. Th
```yml
tests:
- text: <code>IBeforeExceptC</code> should be a function.
testString: 'assert(typeof IBeforeExceptC=="function","<code>IBeforeExceptC</code> should be a function.");'
testString: assert(typeof IBeforeExceptC=='function','<code>IBeforeExceptC</code> should be a function.');
- text: <code>IBeforeExceptC("receive")</code> should return a boolean.
testString: 'assert(typeof IBeforeExceptC("receive")=="boolean","<code>IBeforeExceptC("receive")</code> should return a boolean.");'
testString: assert(typeof IBeforeExceptC("receive")=='boolean','<code>IBeforeExceptC("receive")</code> should return a boolean.');
- text: <code>IBeforeExceptC("receive")</code> should return <code>true</code>.
testString: 'assert.equal(IBeforeExceptC("receive"),true,"<code>IBeforeExceptC("receive")</code> should return <code>true</code>.");'
testString: assert.equal(IBeforeExceptC("receive"),true,'<code>IBeforeExceptC("receive")</code> should return <code>true</code>.');
- text: <code>IBeforeExceptC("science")</code> should return <code>false</code>.
testString: 'assert.equal(IBeforeExceptC("science"),false,"<code>IBeforeExceptC("science")</code> should return <code>false</code>.");'
testString: assert.equal(IBeforeExceptC("science"),false,'<code>IBeforeExceptC("science")</code> should return <code>false</code>.');
- text: <code>IBeforeExceptC("imperceivable")</code> should return <code>true</code>.
testString: 'assert.equal(IBeforeExceptC("imperceivable"),true,"<code>IBeforeExceptC("imperceivable")</code> should return <code>true</code>.");'
testString: assert.equal(IBeforeExceptC("imperceivable"),true,'<code>IBeforeExceptC("imperceivable")</code> should return <code>true</code>.');
- text: <code>IBeforeExceptC("inconceivable")</code> should return <code>true</code>.
testString: 'assert.equal(IBeforeExceptC("inconceivable"),true,"<code>IBeforeExceptC("inconceivable")</code> should return <code>true</code>.");'
testString: assert.equal(IBeforeExceptC("inconceivable"),true,'<code>IBeforeExceptC("inconceivable")</code> should return <code>true</code>.');
- text: <code>IBeforeExceptC("insufficient")</code> should return <code>false</code>.
testString: 'assert.equal(IBeforeExceptC("insufficient"),false,"<code>IBeforeExceptC("insufficient")</code> should return <code>false</code>.");'
testString: assert.equal(IBeforeExceptC("insufficient"),false,'<code>IBeforeExceptC("insufficient")</code> should return <code>false</code>.');
- text: <code>IBeforeExceptC("omniscient")</code> should return <code>false</code>.
testString: 'assert.equal(IBeforeExceptC("omniscient"),false,"<code>IBeforeExceptC("omniscient")</code> should return <code>false</code>.");'
testString: assert.equal(IBeforeExceptC("omniscient"),false,'<code>IBeforeExceptC("omniscient")</code> should return <code>false</code>.');
```

View File

@ -28,19 +28,19 @@ Write a function that takes IBAN string as parameter. If it is valid return true
```yml
tests:
- text: <code>isValid</code> should be a function.
testString: 'assert(typeof isValid=="function","<code>isValid</code> should be a function.");'
- text: <code>isValid(""+tests[0]+"")</code> should return a boolean.
testString: 'assert(typeof isValid(tests[0])=="boolean","<code>isValid(""+tests[0]+"")</code> should return a boolean.");'
- text: <code>isValid(""+tests[0]+"")</code> should return <code>true</code>.
testString: 'assert.equal(isValid(tests[0]),true,"<code>isValid(""+tests[0]+"")</code> should return <code>true</code>.");'
- text: <code>isValid(""+tests[1]+"")</code> should return <code>false</code>.
testString: 'assert.equal(isValid(tests[1]),false,"<code>isValid(""+tests[1]+"")</code> should return <code>false</code>.");'
- text: <code>isValid(""+tests[2]+"")</code> should return <code>false</code>.
testString: 'assert.equal(isValid(tests[2]),false,"<code>isValid(""+tests[2]+"")</code> should return <code>false</code>.");'
- text: <code>isValid(""+tests[3]+"")</code> should return <code>false</code>.
testString: 'assert.equal(isValid(tests[3]),false,"<code>isValid(""+tests[3]+"")</code> should return <code>false</code>.");'
- text: <code>isValid(""+tests[4]+"")</code> should return <code>true</code>.
testString: 'assert.equal(isValid(tests[4]),true,"<code>isValid(""+tests[4]+"")</code> should return <code>true</code>.");'
testString: assert(typeof isValid=='function','<code>isValid</code> should be a function.');
- text: <code>isValid("GB82 WEST 1234 5698 7654 32")</code> should return a boolean.
testString: assert(typeof isValid('GB82 WEST 1234 5698 7654 32')=='boolean','<code>isValid("GB82 WEST 1234 5698 7654 32")</code> should return a boolean.');
- text: <code>isValid("GB82 WEST 1234 5698 7654 32")</code> should return <code>true</code>.
testString: assert.equal(isValid('GB82 WEST 1234 5698 7654 32'),true,'<code>isValid("GB82 WEST 1234 5698 7654 32")</code> should return <code>true</code>.');
- text: <code>isValid("GB82 WEST 1.34 5698 7654 32")</code> should return <code>false</code>.
testString: assert.equal(isValid('GB82 WEST 1.34 5698 7654 32'),false,'<code>isValid("GB82 WEST 1.34 5698 7654 32")</code> should return <code>false</code>.');
- text: <code>isValid("GB82 WEST 1234 5698 7654 325")</code> should return <code>false</code>.
testString: assert.equal(isValid('GB82 WEST 1234 5698 7654 325'),false,'<code>isValid("GB82 WEST 1234 5698 7654 325")</code> should return <code>false</code>.');
- text: <code>isValid("GB82 TEST 1234 5698 7654 32")</code> should return <code>false</code>.
testString: assert.equal(isValid('GB82 TEST 1234 5698 7654 32'),false,'<code>isValid("GB82 TEST 1234 5698 7654 32")</code> should return <code>false</code>.');
- text: <code>isValid("SA03 8000 0000 6080 1016 7519")</code> should return <code>true</code>.
testString: assert.equal(isValid('SA03 8000 0000 6080 1016 7519'),true,'<code>isValid("SA03 8000 0000 6080 1016 7519")</code> should return <code>true</code>.');
```
@ -59,16 +59,6 @@ function isValid (iban) {
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution
@ -87,12 +77,12 @@ function isValid (iban) {
MC:27, MR:27, SM:27, AL:28, AZ:28, CY:28, DO:28, GT:28,
HU:28, LB:28, PL:28, BR:29, PS:29, KW:30, MU:30, MT:31
}
iban = iban.replace(/\s/g, ")
iban = iban.replace(/\s/g, '')
if (!iban.match(/^[\dA-Z]+$/)) return false
var len = iban.length
if (len != ibanLen[iban.substr(0,2)]) return false
iban = iban.substr(4) + iban.substr(0,4)
for (var s=", i=0; i<len; i+=1) s+=parseInt(iban.charAt(i),36)
for (var s='', i=0; i<len; i+=1) s+=parseInt(iban.charAt(i),36)
for (var m=s.substr(0,15)%97, s=s.substr(15); s; s=s.substr(13)) m=(m+s.substr(0,13))%97
return m == 1
}

View File

@ -24,17 +24,17 @@ Write a function that takes a number 'n' as a parameter and returns the identity
```yml
tests:
- text: <code>idMatrix</code> should be a function.
testString: 'assert(typeof idMatrix=="function","<code>idMatrix</code> should be a function.");'
testString: assert(typeof idMatrix=='function','<code>idMatrix</code> should be a function.');
- text: <code>idMatrix(1)</code> should return an array.
testString: 'assert(Array.isArray(idMatrix(1)),"<code>idMatrix(1)</code> should return an array.");'
- text: <code>idMatrix(1)</code> should return <code>"+JSON.stringify(results[0])+"</code>.
testString: 'assert.deepEqual(idMatrix(1),results[0],"<code>idMatrix(1)</code> should return <code>"+JSON.stringify(results[0])+"</code>.");'
- text: <code>idMatrix(2)</code> should return <code>"+JSON.stringify(results[1])+"</code>.
testString: 'assert.deepEqual(idMatrix(2),results[1],"<code>idMatrix(2)</code> should return <code>"+JSON.stringify(results[1])+"</code>.");'
- text: <code>idMatrix(3)</code> should return <code>"+JSON.stringify(results[2])+"</code>.
testString: 'assert.deepEqual(idMatrix(3),results[2],"<code>idMatrix(3)</code> should return <code>"+JSON.stringify(results[2])+"</code>.");'
- text: <code>idMatrix(4)</code> should return <code>"+JSON.stringify(results[3])+"</code>.
testString: 'assert.deepEqual(idMatrix(4),results[3],"<code>idMatrix(4)</code> should return <code>"+JSON.stringify(results[3])+"</code>.");'
testString: assert(Array.isArray(idMatrix(1)),'<code>idMatrix(1)</code> should return an array.');
- text: <code>idMatrix(1)</code> should return <code>'+JSON.stringify(results[0])+'</code>.
testString: assert.deepEqual(idMatrix(1),results[0],'<code>idMatrix(1)</code> should return <code>'+JSON.stringify(results[0])+'</code>.');
- text: <code>idMatrix(2)</code> should return <code>'+JSON.stringify(results[1])+'</code>.
testString: assert.deepEqual(idMatrix(2),results[1],'<code>idMatrix(2)</code> should return <code>'+JSON.stringify(results[1])+'</code>.');
- text: <code>idMatrix(3)</code> should return <code>'+JSON.stringify(results[2])+'</code>.
testString: assert.deepEqual(idMatrix(3),results[2],'<code>idMatrix(3)</code> should return <code>'+JSON.stringify(results[2])+'</code>.');
- text: <code>idMatrix(4)</code> should return <code>'+JSON.stringify(results[3])+'</code>.
testString: assert.deepEqual(idMatrix(4),results[3],'<code>idMatrix(4)</code> should return <code>'+JSON.stringify(results[3])+'</code>.');
```
@ -58,7 +58,10 @@ function idMatrix (n) {
<div id='js-teardown'>
```js
console.info('after the test');
let results=[[ [ 1 ] ],
[ [ 1, 0 ], [ 0, 1 ] ],
[ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ],
[ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ]]
```
</div>

View File

@ -23,21 +23,21 @@ Write a function that takes a number as a parameter and returns 1 or 89 after pe
```yml
tests:
- text: <code>iteratedSquare</code> should be a function.
testString: 'assert(typeof iteratedSquare=="function","<code>iteratedSquare</code> should be a function.");'
testString: assert(typeof iteratedSquare=='function','<code>iteratedSquare</code> should be a function.');
- text: <code>iteratedSquare(4)</code> should return a number.
testString: 'assert(typeof iteratedSquare(4)=="number","<code>iteratedSquare(4)</code> should return a number.");'
testString: assert(typeof iteratedSquare(4)=='number','<code>iteratedSquare(4)</code> should return a number.');
- text: <code>iteratedSquare(4)</code> should return <code>89</code>.
testString: 'assert.equal(iteratedSquare(4),89,"<code>iteratedSquare(4)</code> should return <code>89</code>.");'
testString: assert.equal(iteratedSquare(4),89,'<code>iteratedSquare(4)</code> should return <code>89</code>.');
- text: <code>iteratedSquare(7)</code> should return <code>1</code>.
testString: 'assert.equal(iteratedSquare(7),1,"<code>iteratedSquare(7)</code> should return <code>1</code>.");'
testString: assert.equal(iteratedSquare(7),1,'<code>iteratedSquare(7)</code> should return <code>1</code>.');
- text: <code>iteratedSquare(15)</code> should return <code>89</code>.
testString: 'assert.equal(iteratedSquare(15),89,"<code>iteratedSquare(15)</code> should return <code>89</code>.");'
testString: assert.equal(iteratedSquare(15),89,'<code>iteratedSquare(15)</code> should return <code>89</code>.');
- text: <code>iteratedSquare(20)</code> should return <code>89</code>.
testString: 'assert.equal(iteratedSquare(20),89,"<code>iteratedSquare(20)</code> should return <code>89</code>.");'
testString: assert.equal(iteratedSquare(20),89,'<code>iteratedSquare(20)</code> should return <code>89</code>.');
- text: <code>iteratedSquare(70)</code> should return <code>1</code>.
testString: 'assert.equal(iteratedSquare(70),1,"<code>iteratedSquare(70)</code> should return <code>1</code>.");'
testString: assert.equal(iteratedSquare(70),1,'<code>iteratedSquare(70)</code> should return <code>1</code>.');
- text: <code>iteratedSquare(100)</code> should return <code>1</code>.
testString: 'assert.equal(iteratedSquare(100),1,"<code>iteratedSquare(100)</code> should return <code>1</code>.");'
testString: assert.equal(iteratedSquare(100),1,'<code>iteratedSquare(100)</code> should return <code>1</code>.');
```

View File

@ -29,19 +29,19 @@ Write a function a that takes two strings as parameters and returns the associat
```yml
tests:
- text: <code>jaro</code> should be a function.
testString: 'assert(typeof jaro=="function","<code>jaro</code> should be a function.");'
- text: <code>jaro(""+tests[0][0]+"",""+tests[0][1]+"")</code> should return a number.
testString: 'assert(typeof jaro(tests[0][0],tests[0][1])=="number","<code>jaro()</code> should return a number.");'
- text: <code>jaro(""+tests[0][0]+"",""+tests[0][1]+"")</code> should return <code>"+results[0]+"</code>.
testString: 'assert.equal(jaro(tests[0][0],tests[0][1]),results[0],"<code>jaro(""+tests[0][0]+"",""+tests[0][1]+"")</code> should return <code>"+results[0]+"</code>.");'
- text: <code>jaro(""+tests[1][0]+"",""+tests[1][1]+"")</code> should return <code>"+results[1]+"</code>.
testString: 'assert.equal(jaro(tests[1][0],tests[1][1]),results[1],"<code>jaro(""+tests[1][0]+"",""+tests[1][1]+"")</code> should return <code>"+results[1]+"</code>.");'
- text: <code>jaro(""+tests[2][0]+"",""+tests[2][1]+"")</code> should return <code>"+results[2]+"</code>.
testString: 'assert.equal(jaro(tests[2][0],tests[2][1]),results[2],"<code>jaro(""+tests[2][0]+"",""+tests[2][1]+"")</code> should return <code>"+results[2]+"</code>.");'
- text: <code>jaro(""+tests[3][0]+"",""+tests[3][1]+"")</code> should return <code>"+results[3]+"</code>.
testString: 'assert.equal(jaro(tests[3][0],tests[3][1]),results[3],"<code>jaro(""+tests[3][0]+"",""+tests[3][1]+"")</code> should return <code>"+results[3]+"</code>.");'
- text: <code>jaro(""+tests[4][0]+"",""+tests[4][1]+"")</code> should return <code>"+results[4]+"</code>.
testString: 'assert.equal(jaro(tests[4][0],tests[4][1]),results[4],"<code>jaro(""+tests[4][0]+"",""+tests[4][1]+"")</code> should return <code>"+results[4]+"</code>.");'
testString: assert(typeof jaro=='function','<code>jaro</code> should be a function.');
- text: <code>jaro("MARTHA", "MARHTA")</code> should return a number.
testString: assert(typeof jaro('MARTHA', 'MARHTA')=='number','<code>jaro()</code> should return a number.');
- text: <code>jaro("MARTHA", "MARHTA")</code> should return <code>0.9444444444444445</code>.
testString: assert.equal(jaro('MARTHA', 'MARHTA'), 0.9444444444444445,'<code>jaro("MARTHA", "MARHTA")</code> should return <code>0.9444444444444445</code>.');
- text: <code>jaro("DIXON", "DICKSONX")</code> should return <code>0.7666666666666666</code>.
testString: assert.equal(jaro('DIXON', 'DICKSONX'), 0.7666666666666666,'<code>jaro("DIXON", "DICKSONX")</code> should return <code>0.7666666666666666</code>.');
- text: <code>jaro("JELLYFISH", "SMELLYFISH")</code> should return <code>0.8962962962962964</code>.
testString: assert.equal(jaro('JELLYFISH', 'SMELLYFISH'), 0.8962962962962964,'<code>jaro("JELLYFISH", "SMELLYFISH")</code> should return <code>0.8962962962962964</code>.');
- text: <code>jaro("HELLOS", "CHELLO")</code> should return <code>0.888888888888889</code>.
testString: assert.equal(jaro('HELLOS', 'CHELLO'), 0.888888888888889,'<code>jaro("HELLOS", "CHELLO")</code> should return <code>0.888888888888889</code>.');
- text: <code>jaro("ABCD", "BCDA")</code> should return <code>0.8333333333333334</code>.
testString: assert.equal(jaro('ABCD', 'BCDA'), 0.8333333333333334,'<code>jaro("ABCD", "BCDA")</code> should return <code>0.8333333333333334</code>.');
```
@ -60,16 +60,6 @@ function jaro (s, t) {
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution

View File

@ -21,21 +21,21 @@ jortSort is a function that takes a single array of comparable objects as its ar
```yml
tests:
- text: <code>jortsort</code> should be a function.
testString: 'assert(typeof jortsort=="function","<code>jortsort</code> should be a function.");'
- text: <code>jortsort("+JSON.stringify(tests[0])+")</code> should return a boolean.
testString: 'assert(typeof jortsort(tests[0].slice())=="boolean","<code>jortsort("+JSON.stringify(tests[0])+")</code> should return a boolean.");'
- text: <code>jortsort("+JSON.stringify(tests[0])+")</code> should return <code>true</code>.
testString: 'assert.equal(jortsort(tests[0].slice()),true,"<code>jortsort("+JSON.stringify(tests[0])+")</code> should return <code>true</code>.");'
- text: <code>jortsort("+JSON.stringify(tests[1])+")</code> should return <code>false</code>.
testString: 'assert.equal(jortsort(tests[1].slice()),false,"<code>jortsort("+JSON.stringify(tests[1])+")</code> should return <code>false</code>.");'
- text: <code>jortsort("+JSON.stringify(tests[2])+")</code> should return <code>false</code>.
testString: 'assert.equal(jortsort(tests[2].slice()),false,"<code>jortsort("+JSON.stringify(tests[2])+")</code> should return <code>false</code>.");'
- text: <code>jortsort("+JSON.stringify(tests[3])+")</code> should return <code>true</code>.
testString: 'assert.equal(jortsort(tests[3].slice()),true,"<code>jortsort("+JSON.stringify(tests[3])+")</code> should return <code>true</code>.");'
- text: <code>jortsort("+JSON.stringify(tests[4])+")</code> should return <code>false</code>.
testString: 'assert.equal(jortsort(tests[4].slice()),false,"<code>jortsort("+JSON.stringify(tests[4])+")</code> should return <code>false</code>.");'
- text: <code>jortsort("+JSON.stringify(tests[5])+")</code> should return <code>true</code>.
testString: 'assert.equal(jortsort(tests[5].slice()),true,"<code>jortsort("+JSON.stringify(tests[5])+")</code> should return <code>true</code>.");'
testString: assert(typeof jortsort=='function','<code>jortsort</code> should be a function.');
- text: <code>jortsort([1,2,3,4,5])</code> should return a boolean.
testString: assert(typeof jortsort([1,2,3,4,5])=='boolean','<code>jortsort([1,2,3,4,5])</code> should return a boolean.');
- text: <code>jortsort([1,2,3,4,5])</code> should return <code>true</code>.
testString: assert.equal(jortsort([1,2,3,4,5]),true,'<code>jortsort([1,2,3,4,5])</code> should return <code>true</code>.');
- text: <code>jortsort([1,2,13,4,5])</code> should return <code>false</code>.
testString: assert.equal(jortsort([1,2,13,4,5]),false,'<code>jortsort([1,2,13,4,5])</code> should return <code>false</code>.');
- text: <code>jortsort([12,4,51,2,4])</code> should return <code>false</code>.
testString: assert.equal(jortsort([12,4,51,2,4]),false,'<code>jortsort([12,4,51,2,4])</code> should return <code>false</code>.');
- text: <code>jortsort([1,2])</code> should return <code>true</code>.
testString: assert.equal(jortsort([1,2]),true,'<code>jortsort([1,2])</code> should return <code>true</code>.');
- text: <code>jortsort([5,4,3,2,1])</code> should return <code>false</code>.
testString: assert.equal(jortsort([5,4,3,2,1]),false,'<code>jortsort([5,4,3,2,1])</code> should return <code>false</code>.');
- text: <code>jortsort([1,1,1,1,1])</code> should return <code>true</code>.
testString: assert.equal(jortsort([1,1,1,1,1]),true,'<code>jortsort([1,1,1,1,1])</code> should return <code>true</code>.');
```
@ -54,16 +54,6 @@ function jortsort (array) {
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution

View File

@ -28,19 +28,19 @@ Write a function that takes the initial number of prisoners and 'k' as parameter
```yml
tests:
- text: <code>josephus</code> should be a function.
testString: 'assert(typeof josephus=="function","<code>josephus</code> should be a function.");'
testString: assert(typeof josephus=='function','<code>josephus</code> should be a function.');
- text: <code>josephus(30,3)</code> should return a number.
testString: 'assert(typeof josephus(30,3)=="number","<code>josephus(30,3)</code> should return a number.");'
testString: assert(typeof josephus(30,3)=='number','<code>josephus(30,3)</code> should return a number.');
- text: <code>josephus(30,3)</code> should return <code>29</code>.
testString: 'assert.equal(josephus(30,3),29,"<code>josephus(30,3)</code> should return <code>29</code>.");'
testString: assert.equal(josephus(30,3),29,'<code>josephus(30,3)</code> should return <code>29</code>.');
- text: <code>josephus(30,5)</code> should return <code>3</code>.
testString: 'assert.equal(josephus(30,5),3,"<code>josephus(30,5)</code> should return <code>3</code>.");'
testString: assert.equal(josephus(30,5),3,'<code>josephus(30,5)</code> should return <code>3</code>.');
- text: <code>josephus(20,2)</code> should return <code>9</code>.
testString: 'assert.equal(josephus(20,2),9,"<code>josephus(20,2)</code> should return <code>9</code>.");'
testString: assert.equal(josephus(20,2),9,'<code>josephus(20,2)</code> should return <code>9</code>.');
- text: <code>josephus(17,6)</code> should return <code>2</code>.
testString: 'assert.equal(josephus(17,6),2,"<code>josephus(17,6)</code> should return <code>2</code>.");'
testString: assert.equal(josephus(17,6),2,'<code>josephus(17,6)</code> should return <code>2</code>.');
- text: <code>josephus(29,4)</code> should return <code>2</code>.
testString: 'assert.equal(josephus(29,4),2,"<code>josephus(29,4)</code> should return <code>2</code>.");'
testString: assert.equal(josephus(29,4),2,'<code>josephus(29,4)</code> should return <code>2</code>.');
```

View File

@ -58,11 +58,11 @@ for examples of native data structures.)
```yml
tests:
- text: <code>parseSexpr</code> is a function.
testString: 'assert(typeof parseSexpr === "function", "<code>parseSexpr</code> is a function.");'
- text: '<code>parseSexpr("(data1 data2 data3)")</code> should return ["data1", "data2", "data3"]")'
testString: 'assert.deepEqual(parseSexpr(simpleSExpr), simpleSolution, "<code>parseSexpr("(data1 data2 data3)")</code> should return ["data1", "data2", "data3"]");'
testString: assert(typeof parseSexpr === 'function', '<code>parseSexpr</code> is a function.');
- text: <code>parseSexpr('(data1 data2 data3)')</code> should return ['data1', 'data2', 'data3']")
testString: assert.deepEqual(parseSexpr(simpleSExpr), simpleSolution, "<code>parseSexpr('(data1 data2 data3)')</code> should return ['data1', 'data2', 'data3']");
- text: <code>parseSexpr('(data1 data2 data3)')</code> should return an array with 3 elements")
testString: 'assert.deepEqual(parseSexpr(basicSExpr), basicSolution, "<code>parseSexpr("(data1 data2 data3)")</code> should return an array with 3 elements");'
testString: assert.deepEqual(parseSexpr(basicSExpr), basicSolution, "<code>parseSexpr('(data1 data2 data3)')</code> should return an array with 3 elements");
```
@ -87,7 +87,11 @@ function parseSexpr(str) {
<div id='js-teardown'>
```js
console.info('after the test');
const simpleSExpr = '(data1 data2 data3)';
const simpleSolution = ['data1', 'data2', 'data3'];
const basicSExpr = '((data "quoted data" 123 4.5) (data (!@# (4.5) "(more" "data)")))';
const basicSolution = [["data","\"quoted data\"",123,4.5],["data",["!@#",[4.5],"\"(more\"","\"data)\""]]];
```
</div>
@ -108,7 +112,7 @@ function parseSexpr(str) {
else if (ti == '(') t[i] = '[', c += 1;
else if (ti == ')') t[i] = ']', c -= 1;
else if ((n = +ti) == ti) t[i] = n;
else t[i] = `'${ti.replace('\", '\\\")}'`;
else t[i] = `'${ti.replace('\'', '\\\'')}'`;
if (i > 0 && ti != ']' && t[i - 1].trim() != '(') t.splice(i, 0, ',');
if (!c) if (!o) o = true; else return;
}

View File

@ -77,13 +77,13 @@ challengeType: 5
```yml
tests:
- text: <code>splitCoconuts</code> is a function.
testString: 'assert(typeof splitCoconuts === "function", "<code>splitCoconuts</code> is a function.");'
testString: assert(typeof splitCoconuts === 'function', '<code>splitCoconuts</code> is a function.');
- text: <code>splitCoconuts(5)</code> should return 3121.
testString: 'assert(splitCoconuts(5) === 3121, "<code>splitCoconuts(5)</code> should return 3121.");'
testString: assert(splitCoconuts(5) === 3121, '<code>splitCoconuts(5)</code> should return 3121.');
- text: <code>splitCoconuts(6)</code> should return 233275.
testString: 'assert(splitCoconuts(6) === 233275, "<code>splitCoconuts(6)</code> should return 233275.");'
testString: assert(splitCoconuts(6) === 233275, '<code>splitCoconuts(6)</code> should return 233275.');
- text: <code>splitCoconuts(7)</code> should return 823537.
testString: 'assert(splitCoconuts(7) === 823537, "<code>splitCoconuts(7)</code> should return 823537.");'
testString: assert(splitCoconuts(7) === 823537, '<code>splitCoconuts(7)</code> should return 823537.');
```

View File

@ -51,15 +51,15 @@ challengeType: 5
```yml
tests:
- text: <code>sedol</code> is a function.
testString: 'assert(typeof sedol === "function", "<code>sedol</code> is a function.");'
testString: assert(typeof sedol === 'function', '<code>sedol</code> is a function.');
- text: <code>sedol('a')</code> should return null.")
testString: 'assert(sedol("a") === null, "<code>sedol("a")</code> should return null.");'
testString: assert(sedol('a') === null, "<code>sedol('a')</code> should return null.");
- text: <code>sedol('710889')</code> should return '7108899'.")
testString: 'assert(sedol("710889") === "7108899", "<code>sedol("710889")</code> should return "7108899".");'
testString: assert(sedol('710889') === '7108899', "<code>sedol('710889')</code> should return '7108899'.");
- text: <code>sedol('BOATER')</code> should return null.")
testString: 'assert(sedol("BOATER") === null, "<code>sedol("BOATER")</code> should return null.");'
testString: assert(sedol('BOATER') === null, "<code>sedol('BOATER')</code> should return null.");
- text: <code>sedol('228276')</code> should return '2282765'.")
testString: 'assert(sedol("228276") === "2282765", "<code>sedol("228276")</code> should return "2282765".");'
testString: assert(sedol('228276') === '2282765', "<code>sedol('228276')</code> should return '2282765'.");
```

View File

@ -37,17 +37,17 @@ See also:
```yml
tests:
- text: <code>taxicabNumbers </code> is a function.
testString: 'assert(typeof taxicabNumbers === "function", "<code>taxicabNumbers </code> is a function.");'
testString: assert(typeof taxicabNumbers === 'function', '<code>taxicabNumbers </code> is a function.');
- text: <code>taxicabNumbers </code> should return an array.
testString: 'assert(typeof taxicabNumbers(2) === "object", "<code>taxicabNumbers </code> should return an array.");'
testString: assert(typeof taxicabNumbers(2) === 'object', '<code>taxicabNumbers </code> should return an array.');
- text: <code>taxicabNumbers </code> should return an array of numbers.
testString: 'assert(typeof taxicabNumbers(100)[0] === "number", "<code>taxicabNumbers </code> should return an array of numbers.");'
- text: '<code>taxicabNumbers(4) </code> must return [1729, 4104, 13832, 20683].'
testString: 'assert.deepEqual(taxicabNumbers(4), res4, "<code>taxicabNumbers(4) </code> must return [1729, 4104, 13832, 20683].");'
- text: 'taxicabNumbers(25) should return [1729, 4104, 13832, 20683, 32832, 39312, 40033, 46683, 64232, 65728, 110656, 110808, 134379, 149389, 165464, 171288, 195841, 216027, 216125, 262656, 314496, 320264, 327763, 373464, 402597]'
testString: 'assert.deepEqual(taxicabNumbers(25), res25, "taxicabNumbers(25) should return [1729, 4104, 13832, 20683, 32832, 39312, 40033, 46683, 64232, 65728, 110656, 110808, 134379, 149389, 165464, 171288, 195841, 216027, 216125, 262656, 314496, 320264, 327763, 373464, 402597]");'
- text: 'taxicabNumbers(39) resulting numbers from 20 - 29 should be [314496,320264,327763,373464,402597,439101,443889,513000,513856].'
testString: 'assert.deepEqual(taxicabNumbers(39).slice(20, 29), res39From20To29, "taxicabNumbers(39) resulting numbers from 20 - 29 should be [314496,320264,327763,373464,402597,439101,443889,513000,513856].");'
testString: assert(typeof taxicabNumbers(100)[0] === 'number', '<code>taxicabNumbers </code> should return an array of numbers.');
- text: <code>taxicabNumbers(4) </code> must return [1729, 4104, 13832, 20683].
testString: assert.deepEqual(taxicabNumbers(4), res4, '<code>taxicabNumbers(4) </code> must return [1729, 4104, 13832, 20683].');
- text: taxicabNumbers(25) should return [1729, 4104, 13832, 20683, 32832, 39312, 40033, 46683, 64232, 65728, 110656, 110808, 134379, 149389, 165464, 171288, 195841, 216027, 216125, 262656, 314496, 320264, 327763, 373464, 402597]
testString: assert.deepEqual(taxicabNumbers(25), res25, 'taxicabNumbers(25) should return [1729, 4104, 13832, 20683, 32832, 39312, 40033, 46683, 64232, 65728, 110656, 110808, 134379, 149389, 165464, 171288, 195841, 216027, 216125, 262656, 314496, 320264, 327763, 373464, 402597]');
- text: taxicabNumbers(39) resulting numbers from 20 - 29 should be [314496,320264,327763,373464,402597,439101,443889,513000,513856].
testString: assert.deepEqual(taxicabNumbers(39).slice(20, 29), res39From20To29, 'taxicabNumbers(39) resulting numbers from 20 - 29 should be [314496,320264,327763,373464,402597,439101,443889,513000,513856].');
```
@ -72,7 +72,14 @@ function taxicabNumbers (n) {
<div id='js-teardown'>
```js
console.info('after the test');
const res4 = [1729, 4104, 13832, 20683];
const res25 = [
1729, 4104, 13832, 20683, 32832, 39312, 40033, 46683, 64232, 65728, 110656,
110808, 134379, 149389, 165464, 171288, 195841, 216027, 216125, 262656, 314496, 320264, 327763,
373464, 402597
];
const res39From20To29 = [314496, 320264, 327763, 373464, 402597, 439101, 443889, 513000, 513856];
```
</div>

View File

@ -29,7 +29,7 @@ It should accept three input parameters:
function should output the following array:
</p>
<pre>
['one|uno', ", 'three^^', 'four^|quatro', "]
['one|uno', '', 'three^^', 'four^|quatro', '']
</pre>
</section>
@ -44,13 +44,13 @@ It should accept three input parameters:
```yml
tests:
- text: <code>tokenize</code> is a function.
testString: 'assert(typeof tokenize === "function", "<code>tokenize</code> is a function.");'
testString: assert(typeof tokenize === 'function', '<code>tokenize</code> is a function.');
- text: <code>tokenize</code> should return an array.
testString: 'assert(typeof tokenize("a", "b", "c") === "object", "<code>tokenize</code> should return an array.");'
- text: '<code>tokenize("one^|uno||three^^^^|four^^^|^cuatro|", "|", "^") </code> should return ["one|uno", "", "three^^", "four^|cuatro", ""]")'
testString: 'assert.deepEqual(tokenize(testStr1, "|", "^"), res1, "<code>tokenize("one^|uno||three^^^^|four^^^|^cuatro|", "|", "^") </code> should return ["one|uno", "", "three^^", "four^|cuatro", ""]");'
- text: '<code>tokenize("a@&bcd&ef&&@@hi", "&", "@")</code> should return <code>["a&bcd", "ef", "", "@hi"]</code>'
testString: 'assert.deepEqual(tokenize(testStr2, "&", "@"), res2, "<code>tokenize("a@&bcd&ef&&@@hi", "&", "@")</code> should return <code>["a&bcd", "ef", "", "@hi"]</code>");'
testString: assert(typeof tokenize('a', 'b', 'c') === 'object', '<code>tokenize</code> should return an array.');
- text: <code>tokenize('one^|uno||three^^^^|four^^^|^cuatro|', '|', '^') </code> should return ['one|uno', '', 'three^^', 'four^|cuatro', '']")
testString: assert.deepEqual(tokenize(testStr1, '|', '^'), res1, "<code>tokenize('one^|uno||three^^^^|four^^^|^cuatro|', '|', '^') </code> should return ['one|uno', '', 'three^^', 'four^|cuatro', '']");
- text: <code>tokenize('a@&bcd&ef&&@@hi', '&', '@')</code> should return <code>['a&bcd', 'ef', '', '@hi']</code>
testString: assert.deepEqual(tokenize(testStr2, '&', '@'), res2, '<code>tokenize("a@&bcd&ef&&@@hi", "&", "@")</code> should return <code>["a&bcd", "ef", "", "@hi"]</code>');
```
@ -74,7 +74,12 @@ function tokenize(str, esc, sep) {
<div id='js-teardown'>
```js
console.info('after the test');
const testStr1 = 'one^|uno||three^^^^|four^^^|^cuatro|';
const res1 = ['one|uno', '', 'three^^', 'four^|cuatro', ''];
// TODO add more tests
const testStr2 = 'a@&bcd&ef&&@@hi';
const res2 = ['a&bcd', 'ef', '', '@hi'];
```
</div>
@ -96,14 +101,14 @@ function tokenize(str, charDelim, charEsc) {
return {
esc: blnEscChar,
token: blnBreak ? " : (
a.token + (blnEscChar ? " : x)
token: blnBreak ? '' : (
a.token + (blnEscChar ? '' : x)
),
list: a.list.concat(blnBreak ? a.token : [])
};
}, {
esc: false,
token: ",
token: '',
list: []
});

View File

@ -53,19 +53,19 @@ one could rank the top-rated movie in each genre by calling
```yml
tests:
- text: <code>topRankPerGroup</code> is a function.
testString: 'assert(typeof topRankPerGroup === "function", "<code>topRankPerGroup</code> is a function.");'
testString: assert(typeof topRankPerGroup === 'function', '<code>topRankPerGroup</code> is a function.');
- text: <code>topRankPerGroup</code> returns undefined on negative n values.
testString: 'assert(typeof topRankPerGroup(-1, []) === "undefined", "<code>topRankPerGroup</code> returns undefined on negative n values.");'
testString: assert(typeof topRankPerGroup(-1, []) === 'undefined', '<code>topRankPerGroup</code> returns undefined on negative n values.');
- text: First department must be D050
testString: 'assert.equal(res1[0][0].dept, "D050", "First department must be D050");'
testString: assert.equal(res1[0][0].dept, 'D050', 'First department must be D050');
- text: First department must be D050
testString: 'assert.equal(res1[0][1].salary, 21900, "First department must be D050");'
testString: assert.equal(res1[0][1].salary, 21900, 'First department must be D050');
- text: The last department must be D202
testString: 'assert.equal(res1[3][3].dept, "D202", "The last department must be D202");'
- text: '<code>topRankPerGroup(1, ...)</code> must return only top ranking result per group.'
testString: 'assert.equal(res2[2].length, 1, "<code>topRankPerGroup(1, ...)</code> must return only top ranking result per group.");'
- text: '<code>topRankPerGroup(1, ...)</code> must return only top ranking result per group.'
testString: 'assert.equal(res3[2][1].name, "Maze Runner", "<code>topRankPerGroup(1, ...)</code> must return only top ranking result per group.");'
testString: assert.equal(res1[3][3].dept, 'D202', 'The last department must be D202');
- text: <code>topRankPerGroup(1, ...)</code> must return only top ranking result per group.
testString: assert.equal(res2[2].length, 1, '<code>topRankPerGroup(1, ...)</code> must return only top ranking result per group.');
- text: <code>topRankPerGroup(1, ...)</code> must return only top ranking result per group.
testString: assert.equal(res3[2][1].name, 'Maze Runner', '<code>topRankPerGroup(1, ...)</code> must return only top ranking result per group.');
```
@ -90,7 +90,36 @@ function topRankPerGroup(n, data, groupName, rankName) {
<div id='js-teardown'>
```js
console.info('after the test');
const testData1 = [
{ name: 'Tyler Bennett', id: 'E10297', salary: 32000, dept: 'D101' },
{ name: 'John Rappl', id: 'E21437', salary: 47000, dept: 'D050' },
{ name: 'George Woltman', id: 'E00127', salary: 53500, dept: 'D101' },
{ name: 'Adam Smith', id: 'E63535', salary: 18000, dept: 'D202' },
{ name: 'Claire Buckman', id: 'E39876', salary: 27800, dept: 'D202' },
{ name: 'David McClellan', id: 'E04242', salary: 41500, dept: 'D101' },
{ name: 'Rich Holcomb', id: 'E01234', salary: 49500, dept: 'D202' },
{ name: 'Nathan Adams', id: 'E41298', salary: 21900, dept: 'D050' },
{ name: 'Richard Potter', id: 'E43128', salary: 15900, dept: 'D101' },
{ name: 'David Motsinger', id: 'E27002', salary: 19250, dept: 'D202' },
{ name: 'Tim Sampair', id: 'E03033', salary: 27000, dept: 'D101' },
{ name: 'Kim Arlich', id: 'E10001', salary: 57000, dept: 'D190' },
{ name: 'Timothy Grove', id: 'E16398', salary: 29900, dept: 'D190' }
];
const res1 = topRankPerGroup(10, testData1, 'dept', 'salary');
const testData2 = [
{ name: 'Friday 13th', genre: 'horror', rating: 9.9 },
{ name: "Nightmare on Elm's Street", genre: 'horror', rating: 5.7 },
{ name: 'Titanic', genre: 'drama', rating: 7.3 },
{ name: 'Maze Runner', genre: 'scifi', rating: 7.1 },
{ name: 'Blade runner', genre: 'scifi', rating: 8.9 }
];
const res2 = topRankPerGroup(1, testData2, 'genre', 'rating');
const res3 = topRankPerGroup(2, testData2, 'genre', 'rating');
//console.log(JSON.stringify(topRankPerGroup(10, testData1)));
```
</div>

View File

@ -73,15 +73,15 @@ C.f.:
```yml
tests:
- text: <code>topologicalSort</code> is a function.
testString: 'assert(typeof topologicalSort === "function", "<code>topologicalSort</code> is a function.");'
testString: assert(typeof topologicalSort === 'function', '<code>topologicalSort</code> is a function.');
- text: <code>topologicalSort</code> must return correct library order..
testString: 'assert.deepEqual(topologicalSort(libsSimple), ["bbb", "aaa"], "<code>topologicalSort</code> must return correct library order..");'
testString: assert.deepEqual(topologicalSort(libsSimple), ['bbb', 'aaa'], '<code>topologicalSort</code> must return correct library order..');
- text: <code>topologicalSort</code> must return correct library order..
testString: 'assert.deepEqual(topologicalSort(libsVHDL), solutionVHDL, "<code>topologicalSort</code> must return correct library order..");'
testString: assert.deepEqual(topologicalSort(libsVHDL), solutionVHDL, '<code>topologicalSort</code> must return correct library order..');
- text: <code>topologicalSort</code> must return correct library order..
testString: 'assert.deepEqual(topologicalSort(libsCustom), solutionCustom, "<code>topologicalSort</code> must return correct library order..");'
testString: assert.deepEqual(topologicalSort(libsCustom), solutionCustom, '<code>topologicalSort</code> must return correct library order..');
- text: <code>topologicalSort</code> must ignore unorderable dependencies..
testString: 'assert.deepEqual(topologicalSort(libsUnorderable), solutionUnorderable, "<code>topologicalSort</code> must ignore unorderable dependencies..");'
testString: assert.deepEqual(topologicalSort(libsUnorderable), solutionUnorderable, '<code>topologicalSort</code> must ignore unorderable dependencies..');
```
@ -106,7 +106,45 @@ function topologicalSort(libs) {
<div id='js-teardown'>
```js
console.info('after the test');
const libsSimple =
`aaa bbb
bbb`;
const libsVHDL =
`des_system_lib std synopsys std_cell_lib des_system_lib dw02 dw01 ramlib ieee
dw01 ieee dw01 dware gtech
dw02 ieee dw02 dware
dw03 std synopsys dware dw03 dw02 dw01 ieee gtech
dw04 dw04 ieee dw01 dware gtech
dw05 dw05 ieee dware
dw06 dw06 ieee dware
dw07 ieee dware
dware ieee dware
gtech ieee gtech
ramlib std ieee
std_cell_lib ieee std_cell_lib
synopsys`;
const solutionVHDL = [
'ieee', 'std_cell_lib', 'gtech', 'dware', 'dw07', 'dw06',
'dw05', 'dw02', 'dw01', 'dw04', 'std', 'ramlib', 'synopsys',
'dw03', 'des_system_lib'
];
const libsCustom =
`a b c d
b c d
d c
c base
base`;
const solutionCustom = ['base', 'c', 'd', 'b', 'a'];
const libsUnorderable =
`TestLib Base MainLib
MainLib TestLib
Base`;
const solutionUnorderable = ['Base'];
```
</div>
@ -123,7 +161,7 @@ function topologicalSort(libs) {
// and array of packages on which it depends.
const D = libs
.split('\n')
.map(e => e.split(' ').filter(ep => ep !== "))
.map(e => e.split(' ').filter(ep => ep !== ''))
.reduce((p, c) =>
p.set(c[0], c.filter((e, i) => (i > 0 && e !== c[0] ? e : null))), new Map());
[].concat(...D.values()).forEach(e => {

View File

@ -30,15 +30,15 @@ disc from stack B to A.
```yml
tests:
- text: <code>towerOfHanoi</code> is a function.
testString: 'assert(typeof towerOfHanoi === "function", "<code>towerOfHanoi</code> is a function.");'
- text: '<code>towerOfHanoi(3, ...)</code> should return 7 moves.'
testString: 'assert(res3.length === 7, "<code>towerOfHanoi(3, ...)</code> should return 7 moves.");'
- text: '<code>towerOfHanoi(3, "A", "B", "C")</code> should return [["A","B"],["A","C"],["B","C"],["A","B"],["C","A"],["C","B"],["A","B"]].")'
testString: 'assert.deepEqual(towerOfHanoi(3, "A", "B", "C"), res3Moves, "<code>towerOfHanoi(3, "A", "B", "C")</code> should return [["A","B"],["A","C"],["B","C"],["A","B"],["C","A"],["C","B"],["A","B"]].");'
- text: '<code>towerOfHanoi(5, "X", "Y", "Z")</code> 10th move should be Y -> X.'
testString: 'assert.deepEqual(res5[9], ["Y", "X"], "<code>towerOfHanoi(5, "X", "Y", "Z")</code> 10th move should be Y -> X.");'
- text: '<code>towerOfHanoi(7, "A", "B", "C")</code> first ten moves are [["A","B"],["A","C"],["B","C"],["A","B"],["C","A"],["C","B"],["A","B"],["A","C"],["B","C"],["B","A"]].")'
testString: 'assert.deepEqual(towerOfHanoi(7, "A", "B", "C").slice(0, 10), res7First10Moves, "<code>towerOfHanoi(7, "A", "B", "C")</code> first ten moves are [["A","B"],["A","C"],["B","C"],["A","B"],["C","A"],["C","B"],["A","B"],["A","C"],["B","C"],["B","A"]].");'
testString: assert(typeof towerOfHanoi === 'function', '<code>towerOfHanoi</code> is a function.');
- text: <code>towerOfHanoi(3, ...)</code> should return 7 moves.
testString: assert(res3.length === 7, '<code>towerOfHanoi(3, ...)</code> should return 7 moves.');
- text: <code>towerOfHanoi(3, 'A', 'B', 'C')</code> should return [['A','B'],['A','C'],['B','C'],['A','B'],['C','A'],['C','B'],['A','B']].")
testString: assert.deepEqual(towerOfHanoi(3, 'A', 'B', 'C'), res3Moves, "<code>towerOfHanoi(3, 'A', 'B', 'C')</code> should return [['A','B'],['A','C'],['B','C'],['A','B'],['C','A'],['C','B'],['A','B']].");
- text: <code>towerOfHanoi(5, "X", "Y", "Z")</code> 10th move should be Y -> X.
testString: assert.deepEqual(res5[9], ['Y', 'X'], '<code>towerOfHanoi(5, "X", "Y", "Z")</code> 10th move should be Y -> X.');
- text: <code>towerOfHanoi(7, 'A', 'B', 'C')</code> first ten moves are [['A','B'],['A','C'],['B','C'],['A','B'],['C','A'],['C','B'],['A','B'],['A','C'],['B','C'],['B','A']].")
testString: assert.deepEqual(towerOfHanoi(7, 'A', 'B', 'C').slice(0, 10), res7First10Moves, "<code>towerOfHanoi(7, 'A', 'B', 'C')</code> first ten moves are [['A','B'],['A','C'],['B','C'],['A','B'],['C','A'],['C','B'],['A','B'],['A','C'],['B','C'],['B','A']].");
```
@ -63,7 +63,10 @@ function towerOfHanoi (n, a, b, c) {
<div id='js-teardown'>
```js
console.info('after the test');
const res3 = towerOfHanoi(3, 'A', 'B', 'C');
const res3Moves = [['A', 'B'], ['A', 'C'], ['B', 'C'], ['A', 'B'], ['C', 'A'], ['C', 'B'], ['A', 'B']];
const res5 = towerOfHanoi(5, 'X', 'Y', 'Z');
const res7First10Moves = [['A', 'B'], ['A', 'C'], ['B', 'C'], ['A', 'B'], ['C', 'A'], ['C', 'B'], ['A', 'B'], ['A', 'C'], ['B', 'C'], ['B', 'A']];
```
</div>

View File

@ -28,11 +28,11 @@ invalid inputs (ie vectors of different lengths).
```yml
tests:
- text: dotProduct must be a function
testString: 'assert.equal(typeof crossProduct, "function", "dotProduct must be a function");'
testString: assert.equal(typeof crossProduct, 'function', 'dotProduct must be a function');
- text: dotProduct() must return null
testString: 'assert.equal(crossProduct(), null, "dotProduct() must return null");'
- text: 'crossProduct([1, 2, 3], [4, 5, 6]) must return [-3, 6, -3].'
testString: 'assert.deepEqual(res12, exp12, "crossProduct([1, 2, 3], [4, 5, 6]) must return [-3, 6, -3].");'
testString: assert.equal(crossProduct(), null, 'dotProduct() must return null');
- text: crossProduct([1, 2, 3], [4, 5, 6]) must return [-3, 6, -3].
testString: assert.deepEqual(res12, exp12, 'crossProduct([1, 2, 3], [4, 5, 6]) must return [-3, 6, -3].');
```
@ -56,7 +56,10 @@ function crossProduct() {
<div id='js-teardown'>
```js
console.info('after the test');
const tv1 = [1, 2, 3];
const tv2 = [4, 5, 6];
const res12 = crossProduct(tv1, tv2);
const exp12 = [-3, 6, -3];
```
</div>

View File

@ -30,17 +30,17 @@ invalid inputs (ie vectors of different lengths).
```yml
tests:
- text: dotProduct must be a function
testString: 'assert.equal(typeof dotProduct, "function", "dotProduct must be a function");'
testString: assert.equal(typeof dotProduct, 'function', 'dotProduct must be a function');
- text: dotProduct() must return null
testString: 'assert.equal(dotProduct(), null, "dotProduct() must return null");'
- text: 'dotProduct([[1], [1]]) must return 1.'
testString: 'assert.equal(dotProduct([1], [1]), 1, "dotProduct([[1], [1]]) must return 1.");'
- text: 'dotProduct([[1], [1, 2]]) must return null.'
testString: 'assert.equal(dotProduct([1], [1, 2]), null, "dotProduct([[1], [1, 2]]) must return null.");'
- text: 'dotProduct([1, 3, -5], [4, -2, -1]) must return 3.'
testString: 'assert.equal(dotProduct([1, 3, -5], [4, -2, -1]), 3, "dotProduct([1, 3, -5], [4, -2, -1]) must return 3.");'
testString: assert.equal(dotProduct(), null, 'dotProduct() must return null');
- text: dotProduct([[1], [1]]) must return 1.
testString: assert.equal(dotProduct([1], [1]), 1, 'dotProduct([[1], [1]]) must return 1.');
- text: dotProduct([[1], [1, 2]]) must return null.
testString: assert.equal(dotProduct([1], [1, 2]), null, 'dotProduct([[1], [1, 2]]) must return null.');
- text: dotProduct([1, 3, -5], [4, -2, -1]) must return 3.
testString: assert.equal(dotProduct([1, 3, -5], [4, -2, -1]), 3, 'dotProduct([1, 3, -5], [4, -2, -1]) must return 3.');
- text: <code>dotProduct(...nVectors)</code> should return 156000
testString: 'assert.equal(dotProduct([ 0, 1, 2, 3, 4 ], [ 0, 2, 4, 6, 8 ], [ 0, 3, 6, 9, 12 ], [ 0, 4, 8, 12, 16 ], [ 0, 5, 10, 15, 20 ]), 156000, "<code>dotProduct(...nVectors)</code> should return 156000");'
testString: assert.equal(dotProduct([ 0, 1, 2, 3, 4 ], [ 0, 2, 4, 6, 8 ], [ 0, 3, 6, 9, 12 ], [ 0, 4, 8, 12, 16 ], [ 0, 5, 10, 15, 20 ]), 156000, '<code>dotProduct(...nVectors)</code> should return 156000');
```

View File

@ -15,7 +15,7 @@ Example text:
<pre>
Wrap text using a more sophisticated algorithm such as the Knuth and Plass TeX algorithm.
If your language provides this, you get easy extra credit,
but you "must reference documentation" indicating that the algorithm
but you ''must reference documentation'' indicating that the algorithm
is something better than a simple minimimum length algorithm.
</pre>
<p>
@ -44,17 +44,17 @@ than a simple minimimum length algorithm.
```yml
tests:
- text: wrap must be a function.
testString: 'assert.equal(typeof wrap, "function", "wrap must be a function.");'
testString: assert.equal(typeof wrap, 'function', 'wrap must be a function.');
- text: wrap must return a string.
testString: 'assert.equal(typeof wrap("abc", 10), "string", "wrap must return a string.");'
testString: assert.equal(typeof wrap('abc', 10), 'string', 'wrap must return a string.');
- text: wrap(80) must return 4 lines.
testString: 'assert(wrapped80.split("\n").length === 4, "wrap(80) must return 4 lines.");'
testString: assert(wrapped80.split('\n').length === 4, 'wrap(80) must return 4 lines.');
- text: Your <code>wrap</code> function should return our expected text
testString: 'assert.equal(wrapped80.split("\n")[0], firstRow80, "Your <code>wrap</code> function should return our expected text");'
testString: assert.equal(wrapped80.split('\n')[0], firstRow80, 'Your <code>wrap</code> function should return our expected text');
- text: wrap(42) must return 7 lines.
testString: 'assert(wrapped42.split("\n").length === 7, "wrap(42) must return 7 lines.");'
testString: assert(wrapped42.split('\n').length === 7, 'wrap(42) must return 7 lines.');
- text: Your <code>wrap</code> function should return our expected text
testString: 'assert.equal(wrapped42.split("\n")[0], firstRow42, "Your <code>wrap</code> function should return our expected text");'
testString: assert.equal(wrapped42.split('\n')[0], firstRow42, 'Your <code>wrap</code> function should return our expected text');
```
@ -78,7 +78,19 @@ function wrap (text, limit) {
<div id='js-teardown'>
```js
console.info('after the test');
const text =
`Wrap text using a more sophisticated algorithm such as the Knuth and Plass TeX algorithm.
If your language provides this, you get easy extra credit,
but you ''must reference documentation'' indicating that the algorithm
is something better than a simple minimimum length algorithm.`;
const wrapped80 = wrap(text, 80);
const wrapped42 = wrap(text, 42);
const firstRow80 =
'Wrap text using a more sophisticated algorithm such as the Knuth and Plass TeX';
const firstRow42 = 'Wrap text using a more sophisticated';
```
</div>
@ -91,7 +103,7 @@ console.info('after the test');
```js
function wrap (text, limit) {
const noNewlines = text.replace('\n', ");
const noNewlines = text.replace('\n', '');
if (noNewlines.length > limit) {
// find the last space within limit
const edge = noNewlines.slice(0, limit).lastIndexOf(' ');

View File

@ -39,17 +39,17 @@ See also <a href="http://vimeo.com/45140590">Jim Weirich: Adventures in Function
```yml
tests:
- text: Y must return a function
testString: 'assert.equal(typeof Y(f => n => n), "function", "Y must return a function");'
testString: assert.equal(typeof Y(f => n => n), 'function', 'Y must return a function');
- text: factorial(1) must return 1.
testString: 'assert.equal(factorial(1), 1, "factorial(1) must return 1.");'
testString: assert.equal(factorial(1), 1, 'factorial(1) must return 1.');
- text: factorial(2) must return 2.
testString: 'assert.equal(factorial(2), 2, "factorial(2) must return 2.");'
testString: assert.equal(factorial(2), 2, 'factorial(2) must return 2.');
- text: factorial(3) must return 6.
testString: 'assert.equal(factorial(3), 6, "factorial(3) must return 6.");'
testString: assert.equal(factorial(3), 6, 'factorial(3) must return 6.');
- text: factorial(4) must return 24.
testString: 'assert.equal(factorial(4), 24, "factorial(4) must return 24.");'
testString: assert.equal(factorial(4), 24, 'factorial(4) must return 24.');
- text: factorial(10) must return 3628800.
testString: 'assert.equal(factorial(10), 3628800, "factorial(10) must return 3628800.");'
testString: assert.equal(factorial(10), 3628800, 'factorial(10) must return 3628800.');
```
@ -81,7 +81,7 @@ var factorial = Y(function(f) {
<div id='js-teardown'>
```js
console.info('after the test');
var factorial = Y(f => n => (n > 1 ? n * f(n - 1) : 1));
```
</div>

View File

@ -24,7 +24,7 @@ dropped so that 11 decimal becomes <code>10100</code>.
10100 is not the only way to make 11 from the Fibonacci numbers however
<code>0*13 + 1*8 + 0*5 + 0*3 + 1*2 + 1*1</code> or 010011 would also
represent decimal 11. For a true Zeckendorf number there is the added
restriction that "no two consecutive Fibonacci numbers can be used"
restriction that ''no two consecutive Fibonacci numbers can be used''
which leads to the former unique solution.
</p>
<p>
@ -44,9 +44,9 @@ which leads to the former unique solution.
```yml
tests:
- text: zeckendorf must be function
testString: 'assert.equal(typeof zeckendorf, "function", "zeckendorf must be function");'
testString: assert.equal(typeof zeckendorf, 'function', 'zeckendorf must be function');
- text: Your <code>zeckendorf</code> function should return the correct answer
testString: 'assert.deepEqual(answer, solution20, "Your <code>zeckendorf</code> function should return the correct answer");'
testString: assert.deepEqual(answer, solution20, 'Your <code>zeckendorf</code> function should return the correct answer');
```
@ -70,7 +70,19 @@ function zeckendorf(n) {
<div id='js-teardown'>
```js
console.info('after the test');
const range = (m, n) => (
Array.from({
length: Math.floor(n - m) + 1
}, (_, i) => m + i)
);
const solution20 = [
'1', '10', '100', '101', '1000', '1001', '1010', '10000', '10001',
'10010', '10100', '10101', '100000', '100001', '100010', '100100', '100101',
'101000', '101001', '101010'
];
const answer = range(1, 20).map(zeckendorf);
```
</div>

View File

@ -73,8 +73,8 @@ All pixels are again tested and pixels satisfying all the following conditions a
(0) The pixel is black and has eight neighbours
(1) $2 <= B(P1) <= 6$
(2) $A(P1) = 1$
(3) At least one of P2 and P4 and "'P8"' is white
(4) At least one of "'P2"' and P6 and P8 is white
(3) At least one of P2 and P4 and '''P8''' is white
(4) At least one of '''P2''' and P6 and P8 is white
After iterating over the image and collecting all the pixels satisfying all step 2 conditions, all these condition satisfying pixels are again set to white.
Iteration:
If any pixels were set in this round of either step 1 or step 2 then all steps are repeated until no image pixels are so changed.
@ -95,13 +95,13 @@ Write a routine to perform Zhang-Suen thinning on an image matrix of ones and ze
```yml
tests:
- text: <code>thinImage</code> must be a function
testString: 'assert.equal(typeof thinImage, "function", "<code>thinImage</code> must be a function");'
testString: assert.equal(typeof thinImage, 'function', '<code>thinImage</code> must be a function');
- text: <code>thinImage</code> must return an array
testString: 'assert(Array.isArray(result), "<code>thinImage</code> must return an array");'
testString: assert(Array.isArray(result), '<code>thinImage</code> must return an array');
- text: <code>thinImage</code> must return an array of strings
testString: 'assert.equal(typeof result[0], "string", "<code>thinImage</code> must return an array of strings");'
testString: assert.equal(typeof result[0], 'string', '<code>thinImage</code> must return an array of strings');
- text: <code>thinImage</code> must return an array of strings
testString: 'assert.deepEqual(result, expected, "<code>thinImage</code> must return an array of strings");'
testString: assert.deepEqual(result, expected, '<code>thinImage</code> must return an array of strings');
```
@ -145,7 +145,46 @@ function thinImage(image) {
<div id='js-teardown'>
```js
console.info('after the test');
const imageForTests = [
' ',
' ################# ############# ',
' ################## ################ ',
' ################### ################## ',
' ######## ####### ################### ',
' ###### ####### ####### ###### ',
' ###### ####### ####### ',
' ################# ####### ',
' ################ ####### ',
' ################# ####### ',
' ###### ####### ####### ',
' ###### ####### ####### ',
' ###### ####### ####### ###### ',
' ######## ####### ################### ',
' ######## ####### ###### ################## ###### ',
' ######## ####### ###### ################ ###### ',
' ######## ####### ###### ############# ###### ',
' '];
const expected = [
' ',
' ',
' # ########## ####### ',
' ## # #### # ',
' # # ## ',
' # # # ',
' # # # ',
' # # # ',
' ############ # ',
' # # # ',
' # # # ',
' # # # ',
' # # # ',
' # ## ',
' # ############ ',
' ### ### ',
' ',
' '
];
const result = thinImage(imageForTests);
```
</div>

View File

@ -6,11 +6,11 @@ challengeType: 5
## Description
<section id='description'>
A &nbsp; "zig-zag" &nbsp; array is a square arrangement of the first &nbsp;
A &nbsp; ''zig-zag'' &nbsp; array is a square arrangement of the first &nbsp;
$N^2$ &nbsp; integers, &nbsp; where the
numbers increase sequentially as you zig-zag along the array's &nbsp;
<a href="https://en.wiktionary.org/wiki/antidiagonal">anti-diagonals</a>.
For example, given &nbsp; "'5"', &nbsp; produce this array:
For example, given &nbsp; '''5''', &nbsp; produce this array:
<pre>
0 1 5 6 14
2 4 7 13 15
@ -33,17 +33,17 @@ corresponding matrix as two-dimensional array.
```yml
tests:
- text: ZigZagMatrix must be a function
testString: 'assert.equal(typeof ZigZagMatrix, "function", "ZigZagMatrix must be a function");'
testString: assert.equal(typeof ZigZagMatrix, 'function', 'ZigZagMatrix must be a function');
- text: ZigZagMatrix should return array
testString: 'assert.equal(typeof ZigZagMatrix(1), "object", "ZigZagMatrix should return array");'
testString: assert.equal(typeof ZigZagMatrix(1), 'object', 'ZigZagMatrix should return array');
- text: ZigZagMatrix should return an array of nestes arrays
testString: 'assert.equal(typeof ZigZagMatrix(1)[0], "object", "ZigZagMatrix should return an array of nestes arrays");'
- text: 'ZigZagMatrix(1) should return [[0]]'
testString: 'assert.deepEqual(ZigZagMatrix(1), zm1, "ZigZagMatrix(1) should return [[0]]");'
- text: 'ZigZagMatrix(2) should return [[0, 1], [2, 3]]'
testString: 'assert.deepEqual(ZigZagMatrix(2), zm2, "ZigZagMatrix(2) should return [[0, 1], [2, 3]]");'
testString: assert.equal(typeof ZigZagMatrix(1)[0], 'object', 'ZigZagMatrix should return an array of nestes arrays');
- text: ZigZagMatrix(1) should return [[0]]
testString: assert.deepEqual(ZigZagMatrix(1), zm1, 'ZigZagMatrix(1) should return [[0]]');
- text: ZigZagMatrix(2) should return [[0, 1], [2, 3]]
testString: assert.deepEqual(ZigZagMatrix(2), zm2, 'ZigZagMatrix(2) should return [[0, 1], [2, 3]]');
- text: ZigZagMatrix(5) must return specified matrix
testString: 'assert.deepEqual(ZigZagMatrix(5), zm5, "ZigZagMatrix(5) must return specified matrix");'
testString: assert.deepEqual(ZigZagMatrix(5), zm5, 'ZigZagMatrix(5) must return specified matrix');
```
@ -68,7 +68,15 @@ function ZigZagMatrix(n) {
<div id='js-teardown'>
```js
console.info('after the test');
const zm1 = [[0]];
const zm2 = [[0, 1], [2, 3]];
const zm5 = [
[0, 1, 5, 6, 14],
[2, 4, 7, 13, 15],
[3, 8, 12, 16, 21],
[9, 11, 17, 20, 22],
[10, 18, 19, 23, 24]
];
```
</div>