fix(challenge-md): Fix quotes that failed in the transform
This commit is contained in:
committed by
mrugesh mohapatra
parent
392b28fa55
commit
a859035023
@ -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.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.deepEqual(getDPA(20000), solution, "<code>getDPA(20000)</code> should equal [15043, 4, 4953]");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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(testFn(5) === 5.5, "Passing in the values 3, -4, 1.5, and 5 should return 5.5.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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(ack(3, 3) === 61, "<code>ack(3, 3)</code> should return 61.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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: ");'
|
||||
|
||||
```
|
||||
|
||||
@ -131,10 +131,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;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ challengeType: 5
|
||||
Two integers $N$ and $M$ are said to be <a href="https://en.wikipedia.org/wiki/Amicable numbers" title="wp: Amicable numbers">amicable pairs</a> if $N \neq M$ and the sum of the <a href="http://rosettacode.org/wiki/Proper divisors" title="Proper divisors">proper divisors</a> of $N$ ($\mathrm{sum}(\mathrm{propDivs}(N))$) $= M$ as well as $\mathrm{sum}(\mathrm{propDivs}(M)) = N$.
|
||||
Example:
|
||||
1184 and 1210 are an amicable pair, with proper divisors:
|
||||
1, 2, 4, 8, 16, 32, 37, 74, 148, 296, 592 and
|
||||
1, 2, 4, 8, 16, 32, 37, 74, 148, 296, 592 and
|
||||
1, 2, 5, 10, 11, 22, 55, 110, 121, 242, 605 respectively.
|
||||
Task:
|
||||
Calculate and show here the Amicable pairs below 20,000 (there are eight).
|
||||
@ -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.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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.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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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>'');'
|
||||
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.deepEqual(mode(arr2).sort(), [1, 4], "<code>mode([1, 2, 4, 4, 1])</code> should equal <code>[1, 4]</code>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.deepEqual(pythagoreanMeans(range1), answer1, "<code>pythagoreanMeans([1, 2, ..., 10])</code> should equal the same output above.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.equal(rms(arr1), answer1, "<code>rms([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])</code> should equal <code>6.2048368229954285</code>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.equal(babbage(babbageAns, endDigits), answer, "<code>babbage(99736, 269696)</code> should not return 99736 (there is a smaller answer).");'
|
||||
|
||||
```
|
||||
|
||||
@ -66,7 +66,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
|
||||
|
@ -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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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(!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.");'
|
||||
|
||||
```
|
||||
|
||||
@ -102,12 +102,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;
|
||||
}
|
||||
|
@ -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.'');'
|
||||
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>.'');'
|
||||
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>'');'
|
||||
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>'');'
|
||||
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>'');'
|
||||
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.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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -65,7 +65,7 @@ References and further readings:
|
||||
<a href="http://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html" title="link: http://www.cs.mcgill.ca/~cs251/ClosestPair/ClosestPairDQ.html">Closest Pair (McGill)</a>
|
||||
<a href="http://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf" title="link: http://www.cs.ucsb.edu/~suri/cs235/ClosestPair.pdf">Closest Pair (UCSB)</a>
|
||||
<a href="http://classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf" title="link: http://classes.cec.wustl.edu/~cse241/handouts/closestpair.pdf">Closest pair (WUStL)</a>
|
||||
<a href="http://www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt" title="link: http://www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt">Closest pair (IUPUI)</a>
|
||||
<a href="http://www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt" title="link: http://www.cs.iupui.edu/~xkzou/teaching/CS580/Divide-and-conquer-closestPair.ppt">Closest pair (IUPUI)</a>
|
||||
<p>For the input, expect the argument to be an array of objects (points) with <code>x</code> and <code>y</code> members set to numbers. For the output, return an object containing the key:value pairs for <code>distance</code> and <code>pair</code> (i.e., the pair of two closest points).</p>
|
||||
</section>
|
||||
|
||||
@ -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.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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>.'');'
|
||||
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.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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.'');'
|
||||
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 "{}".'');'
|
||||
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}".'');'
|
||||
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}".'');'
|
||||
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.equal(quibble(testCases[3]), results[3], "<code>quibble(["ABC", "DEF", "G", "H"])</code> should return "{ABC,DEF,G and H}".");'
|
||||
|
||||
```
|
||||
|
||||
@ -82,7 +82,7 @@ function quibble (words) {
|
||||
return "{" +
|
||||
words.slice(0, words.length - 1).join(",") +
|
||||
(words.length > 1 ? " and " : "") +
|
||||
(words[words.length - 1] || '') +
|
||||
(words[words.length - 1] || ") +
|
||||
"}";
|
||||
}
|
||||
|
||||
|
@ -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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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(!azSorted(testCases[4]), "<code>azSorted(["BB", "AA"])</code> returns false.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.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>.'');'
|
||||
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[2]), results[2], "<code>convertSeconds(6000000)</code> should return <code>9 wk, 6 d, 10 hr, 40 min</code>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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.equal(countSubstring(testCases[2], searchString[2]), results[2], "<code>countSubstring("abaabba*bbaba*bbab", "a*b")</code> should return <code>2</code>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -9,10 +9,10 @@ challengeType: 5
|
||||
<p>There are four types of common coins in <a href="https://en.wikipedia.org/wiki/United_States" title="link: https://en.wikipedia.org/wiki/United_States">US</a> currency:</p>
|
||||
quarters (25 cents)
|
||||
dimes (10 cents)
|
||||
nickels (5 cents), and
|
||||
pennies (1 cent)
|
||||
nickels (5 cents), and
|
||||
pennies (1 cent)
|
||||
<p>There are six ways to make change for 15 cents:</p>
|
||||
A dime and a nickel
|
||||
A dime and a nickel
|
||||
A dime and 5 pennies
|
||||
3 nickels
|
||||
2 nickels and 5 pennies
|
||||
@ -21,7 +21,7 @@ A nickel and 10 pennies
|
||||
Task:
|
||||
<p>Implement a function to determine how many ways there are to make change for a dollar using these common coins? (1 dollar = 100 cents).</p>
|
||||
Reference:
|
||||
<a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_Temp_52" title="link: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_Temp_52">an algorithm from MIT Press</a>.
|
||||
<a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_Temp_52" title="link: http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-11.html#%_sec_Temp_52">an algorithm from MIT Press</a>.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
@ -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.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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>.'');'
|
||||
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.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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -24,11 +24,11 @@ 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);'
|
||||
|
||||
|
@ -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(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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.'');'
|
||||
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]'');'
|
||||
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.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]");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -15,7 +15,7 @@ $rand_n$ is in range 0 to 32767.
|
||||
<p>The algorithm follows:</p>Seed the RNG with the number of the deal.
|
||||
Create an <a href="http://rosettacode.org/wiki/array" title="array">array</a> of 52 cards: Ace of Clubs, Ace of Diamonds, Ace of Hearts, Ace of Spades, 2 of Clubs, 2 of Diamonds, and so on through the ranks: Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King. The array indexes are 0 to 51, with Ace of Clubs at 0, and King of Spades at 51.
|
||||
Until the array is empty:
|
||||
Choose a random card at index ≡ next random number (mod array length).
|
||||
Choose a random card at index ≡ next random number (mod array length).
|
||||
Swap this random card with the last card of the array.
|
||||
Remove this random card from the array. (Array length goes down by 1.)
|
||||
Deal this random card.
|
||||
@ -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.'');'
|
||||
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"'');'
|
||||
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.deepEqual(dealFreeCell(617), game617, "<code>dealFreeCell(617)</code> should return an array identical to example "Game #617"");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.'');'
|
||||
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.deepEqual(deepcopy(obj3), obj3, "When passed an object containing another object, should return a deep copy of the object.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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();
|
||||
|
@ -9,7 +9,7 @@ challengeType: 5
|
||||
<p>There is a highly organized city that has decided to assign a number to each of their departments:</p>
|
||||
Police department
|
||||
Sanitation department
|
||||
Fire department
|
||||
Fire department
|
||||
<p>Each department can have a number between 1 and 7 (inclusive).</p><p>The three department numbers are to be unique (different from each other) and must add up to the number 12.</p><p>The Chief of the Police doesn't like odd numbers and wants to have an even number for his department.</p>
|
||||
Task:
|
||||
<p>Write a program which outputs all valid combinations:</p>
|
||||
@ -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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.deepEqual(combinations(nums, total), result, "<code>combinations([1, 2, 3, 4, 5, 6, 7], 12)</code> should return all valid combinations.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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(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 + '!' : ")
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -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.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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.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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.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>'');'
|
||||
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>'');'
|
||||
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([7700, 8000], false), 11, "<code>emirps([7700,8000],true)</code> should return <code>11</code>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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.deepEqual(equilibrium(tests[5]), ans[5], "<code>equilibrium([])</code> should return <code>[]</code>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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.equal(eth_mult(63, 74), 4662, "<code>eth_mult(63,74)</code> should return <code>4662</code>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.equal(eulersMethod(0, 100, 100, 10), 20.000472392, "<code>eulersMethod(0, 100, 100, 10)</code> should return 20.000472392.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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.equal(binom(12, 8), 495, "<code>binom(12,8)</code> should return 495.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -84,7 +84,7 @@ Next phase of applying1@1 -> x,@y
|
||||
++ -> +
|
||||
Termination cleanup for addition_1 -> 1
|
||||
1+_ -> 1
|
||||
_+_ ->
|
||||
_+_ ->
|
||||
</pre>
|
||||
<p>Sample text of:</p>
|
||||
<p> <code> _1111*11111_ </code></p>
|
||||
@ -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.'');'
|
||||
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.".'');'
|
||||
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.".'');'
|
||||
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.".'');'
|
||||
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".'');'
|
||||
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.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".");'
|
||||
|
||||
```
|
||||
|
||||
@ -167,7 +167,7 @@ function markov(rules,test) {
|
||||
let origTest = test;
|
||||
|
||||
let captures = [];
|
||||
|
||||
|
||||
rules.forEach(function(rule){
|
||||
let m = pattern.exec(rule);
|
||||
for (let j = 0; j < m.length; j++)
|
||||
|
@ -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'');'
|
||||
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"'');'
|
||||
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.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>'');'
|
||||
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(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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -14,8 +14,8 @@ For example :
|
||||
3! = 3*2*1 = 6
|
||||
4! = 4*3*2*1 = 24
|
||||
</p>
|
||||
<p>Note :
|
||||
0! = 1
|
||||
<p>Note :
|
||||
0! = 1
|
||||
</p>
|
||||
</section>
|
||||
|
||||
@ -30,9 +30,9 @@ 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.");'
|
||||
- text: <code>factorial(3)</code> should return 120.")
|
||||
|
@ -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");'
|
||||
|
||||
```
|
||||
|
||||
@ -86,7 +86,7 @@ function check_mersenne (p) {
|
||||
|
||||
|
||||
```js
|
||||
function check_mersenne(p){
|
||||
function check_mersenne(p){
|
||||
function isPrime(value){
|
||||
for (let i=2; i < value; i++){
|
||||
if (value % i == 0){
|
||||
@ -97,7 +97,7 @@ function check_mersenne(p){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function trial_factor(base, exp, mod){
|
||||
let square, bits;
|
||||
square = 1;
|
||||
@ -107,7 +107,7 @@ function check_mersenne(p){
|
||||
}
|
||||
return (square == 1);
|
||||
}
|
||||
|
||||
|
||||
function mersenne_factor(p){
|
||||
let limit, k, q;
|
||||
limit = Math.sqrt(Math.pow(2,p) - 1);
|
||||
|
@ -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.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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.deepEqual(factors(64), ans[2], "<code>factors(64)</code> should return <code>[1,2,4,8,16,32,64]</code>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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'');'
|
||||
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>'');'
|
||||
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>'');'
|
||||
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.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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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>.'');'
|
||||
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.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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -25,9 +25,9 @@ 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.");'
|
||||
- text: <code>fibonacci(5)</code> should return 3.")
|
||||
|
@ -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>.");'
|
||||
|
||||
```
|
||||
|
||||
@ -66,16 +66,16 @@ console.info('after the test');
|
||||
function fibWord(n) {
|
||||
function entropy(s) {
|
||||
//create an object containing each individual char
|
||||
//and the amount of iterations per char
|
||||
//and the amount of iterations per char
|
||||
function prob(s) {
|
||||
var h = Object.create(null);
|
||||
s.split('').forEach(function(c) {
|
||||
h[c] && h[c]++ || (h[c] = 1);
|
||||
h[c] && h[c]++ || (h[c] = 1);
|
||||
});
|
||||
return h;
|
||||
}
|
||||
|
||||
s = s.toString(); //just in case
|
||||
s = s.toString(); //just in case
|
||||
var e = 0, l = s.length, h = prob(s);
|
||||
|
||||
for (var i in h ) {
|
||||
@ -85,7 +85,7 @@ function fibWord(n) {
|
||||
return e;
|
||||
}
|
||||
var wOne = "1", wTwo = "0", wNth = [wOne, wTwo], w = "", o = [];
|
||||
|
||||
|
||||
for (var i = 0; i < n; i++) {
|
||||
if (i === 0 || i === 1) {
|
||||
w = wNth[i];
|
||||
@ -95,7 +95,7 @@ function fibWord(n) {
|
||||
}
|
||||
var l = w.length;
|
||||
var e = entropy(w);
|
||||
|
||||
|
||||
if (l <= 21) {
|
||||
o.push({
|
||||
N: i + 1,
|
||||
@ -110,7 +110,7 @@ function fibWord(n) {
|
||||
Entropy: e,
|
||||
Word: "..."
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
@ -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(""+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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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("+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>.")'
|
||||
|
||||
```
|
||||
|
||||
@ -75,7 +75,7 @@ function gamma(x) {
|
||||
771.32342877765313, -176.61502916214059, 12.507343278686905,
|
||||
-0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7
|
||||
];
|
||||
|
||||
|
||||
var g = 7;
|
||||
if (x < 0.5) {
|
||||
return Math.PI / (Math.sin(Math.PI * x) * gamma(1 - x));
|
||||
@ -87,7 +87,7 @@ function gamma(x) {
|
||||
for (var i = 1; i < p.length; i++) {
|
||||
a += p[i] / (x + i);
|
||||
}
|
||||
|
||||
|
||||
var result=Math.sqrt(2 * Math.PI) * Math.pow(t, x + 0.5) * Math.exp(-t) * a;
|
||||
|
||||
return result;
|
||||
|
@ -19,20 +19,20 @@ 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>.'');'
|
||||
- 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>.");'
|
||||
|
||||
```
|
||||
|
||||
@ -76,7 +76,7 @@ function gaussianElimination(A, b) {
|
||||
var n = A.length
|
||||
var idx = new Array(n) // Output vector with row permutations from partial pivoting
|
||||
var vv = new Array(n) // Scaling information
|
||||
|
||||
|
||||
for (var i=0; i<n; i++) {
|
||||
var max = 0
|
||||
for (var j=0; j<n; j++) {
|
||||
@ -86,7 +86,7 @@ function gaussianElimination(A, b) {
|
||||
if (max == 0) return // Singular Matrix!
|
||||
vv[i] = 1 / max // Scaling
|
||||
}
|
||||
|
||||
|
||||
var Acpy = new Array(n)
|
||||
for (var i=0; i<n; i++) {
|
||||
var Ai = A[i]
|
||||
@ -95,7 +95,7 @@ function gaussianElimination(A, b) {
|
||||
Acpy[i] = Acpyi
|
||||
}
|
||||
A = Acpy
|
||||
|
||||
|
||||
var tiny = 1e-20 // in case pivot element is zero
|
||||
for (var i=0; ; i++) {
|
||||
for (var j=0; j<i; j++) {
|
||||
@ -133,7 +133,7 @@ function gaussianElimination(A, b) {
|
||||
}
|
||||
return {A:A, idx:idx, d:d}
|
||||
}
|
||||
|
||||
|
||||
// Lower Upper Back Substitution
|
||||
function lubksb(lu, b) {
|
||||
// solves the set of n linear equations A*x = b.
|
||||
@ -145,7 +145,7 @@ function gaussianElimination(A, b) {
|
||||
var bcpy = new Array(n)
|
||||
for (var i=0; i<b.length; i+=1) bcpy[i] = b[i]
|
||||
b = bcpy
|
||||
|
||||
|
||||
for (var ii=-1, i=0; i<n; i++) {
|
||||
var ix = idx[i]
|
||||
var sum = b[ix]
|
||||
|
@ -23,24 +23,24 @@ 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>.'');'
|
||||
- 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>.");'
|
||||
|
||||
```
|
||||
|
||||
@ -77,13 +77,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();
|
||||
}
|
||||
|
||||
|
@ -19,20 +19,20 @@ 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.'');'
|
||||
- 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>.");'
|
||||
- text: "'<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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -24,20 +24,20 @@ 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.'');'
|
||||
- text: '''<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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- text: "'<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.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -7,12 +7,12 @@ challengeType: 5
|
||||
## Description
|
||||
<section id='description'>
|
||||
<a href="https://en.wikipedia.org/wiki/Gray code">Gray code</a> is a form of binary encoding where transitions between consecutive numbers differ by only one bit.
|
||||
This is a useful encoding for reducing hardware data hazards with values that change rapidly and/or connect to slower hardware as inputs.
|
||||
It is also useful for generating inputs for <a href="https://en.wikipedia.org/wiki/Karnaugh map">Karnaugh maps</a> in order from left to right or top to bottom.
|
||||
Create a function to encode a number to and decode a number from Gray code. The function should will have 2 parameters.
|
||||
This is a useful encoding for reducing hardware data hazards with values that change rapidly and/or connect to slower hardware as inputs.
|
||||
It is also useful for generating inputs for <a href="https://en.wikipedia.org/wiki/Karnaugh map">Karnaugh maps</a> in order from left to right or top to bottom.
|
||||
Create a function to encode a number to and decode a number from Gray code. The function should will have 2 parameters.
|
||||
The first would be a boolean. The function should encode for true and decode for false. The second parameter would be the number to be encoded/decoded.
|
||||
Display the normal binary representations, Gray code representations, and decoded Gray code values for all 5-bit binary numbers (0-31 inclusive, leading 0's not necessary).
|
||||
There are many possible Gray codes. The following encodes what is called "binary reflected Gray code."<br>Encoding (MSB is bit 0, b is binary, g is Gray code):
|
||||
There are many possible Gray codes. The following encodes what is called "binary reflected Gray code."<br>Encoding (MSB is bit 0, b is binary, g is Gray code):
|
||||
<code><br>if b[i-1] = 1<br><span style="padding-left:1em">g[i] = not b[i]</span><br>else<br><span style="padding-left:1em">g[i] = b[i]</span><br>
|
||||
</code> Or: <br><code> g = b xor (b logically right shifted 1 time)</code><br>Decoding (MSB is bit 0, b is binary, g is Gray code): <br>
|
||||
<code>b[0] = g[0]<br>for other bits:<br>b[i] = g[i] xor b[i-1]<br></code>
|
||||
@ -28,22 +28,22 @@ 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.'');'
|
||||
- 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.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- text: "'<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.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -19,22 +19,22 @@ 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.'');'
|
||||
- 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.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- text: "'<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.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,22 +20,22 @@ 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>.'');'
|
||||
- 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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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.deepEqual(hailstoneSequence(), res, "<code>hailstoneSequence()</code> should return <code>[[27,82,41,124,8,4,2,1], [351, 77031]]</code>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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(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.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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>'');'
|
||||
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>'');'
|
||||
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>'');'
|
||||
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.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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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>");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -23,22 +23,22 @@ 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.'');'
|
||||
- text: '''<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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- text: "'<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.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -27,20 +27,20 @@ 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>.'');'
|
||||
- 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>.");'
|
||||
|
||||
```
|
||||
|
||||
@ -87,12 +87,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
|
||||
}
|
||||
|
@ -23,18 +23,18 @@ 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.'');'
|
||||
- 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>.'');'
|
||||
- text: "'<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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -22,22 +22,22 @@ 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.'');'
|
||||
- text: '''<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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- text: "'<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.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -28,20 +28,20 @@ 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>.'');'
|
||||
- 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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -20,22 +20,22 @@ 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>.'');'
|
||||
- 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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -27,20 +27,20 @@ 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.'');'
|
||||
- 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.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- 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>.'');'
|
||||
- text: "'<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.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
- 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>.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -40,7 +40,7 @@ Note that with the exception of “<tt>()"</tt>” (“<tt>\</tt>” if escaping
|
||||
</p>
|
||||
<p>
|
||||
and turn it into a native datastructure. (see the
|
||||
<a href="http://rosettacode.org/wiki/#Pike" title="#Pike">Pike</a>,
|
||||
<a href="http://rosettacode.org/wiki/#Pike" title="#Pike">Pike</a>,
|
||||
<a href="http://rosettacode.org/wiki/#Python" title="#Python">Python</a> and
|
||||
<a href="http://rosettacode.org/wiki/#Ruby" title="#Ruby">Ruby</a> implementations
|
||||
for examples of native data structures.)
|
||||
@ -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");'
|
||||
|
||||
```
|
||||
|
||||
@ -108,7 +108,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;
|
||||
}
|
||||
|
@ -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.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -9,7 +9,7 @@ challengeType: 5
|
||||
Task:
|
||||
|
||||
<p>
|
||||
For each number list of 6-digit
|
||||
For each number list of 6-digit
|
||||
<a href="https://en.wikipedia.org/wiki/SEDOL" title="wp: SEDOL">SEDOL</a>s,
|
||||
calculate and append the checksum digit.
|
||||
</p>
|
||||
@ -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".");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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.'');'
|
||||
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].'');'
|
||||
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]'');'
|
||||
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.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].");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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>");'
|
||||
|
||||
```
|
||||
|
||||
@ -96,14 +96,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: []
|
||||
});
|
||||
|
||||
|
@ -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'');'
|
||||
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.'');'
|
||||
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(res3[2][1].name, "Maze Runner", "<code>topRankPerGroup(1, ...)</code> must return only top ranking result per group.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -7,12 +7,12 @@ challengeType: 5
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>
|
||||
Given a mapping between items, and items they depend on, a
|
||||
<a href="https://en.wikipedia.org/wiki/Topological sorting" title="wp: Topological sorting">topological sort</a> orders
|
||||
Given a mapping between items, and items they depend on, a
|
||||
<a href="https://en.wikipedia.org/wiki/Topological sorting" title="wp: Topological sorting">topological sort</a> orders
|
||||
items so that no item precedes an item it depends upon.
|
||||
</p>
|
||||
<p>
|
||||
The compiling of a library in the
|
||||
The compiling of a library in the
|
||||
<a href="https://en.wikipedia.org/wiki/VHDL" title="wp: VHDL">VHDL</a> language
|
||||
has the constraint that a library must be compiled after any library it depends on.
|
||||
</p>
|
||||
@ -20,9 +20,9 @@ Task:
|
||||
<p>
|
||||
Write a function that will return a valid compile order of VHDL libraries from their dependencies.
|
||||
</p>
|
||||
Assume library names are single words.
|
||||
Assume library names are single words.
|
||||
Items mentioned as only dependents have no dependents of their own, but their order of compiling must be given.
|
||||
Any self dependencies should be ignored.
|
||||
Any self dependencies should be ignored.
|
||||
Any un-orderable dependencies should be ignored.
|
||||
<p>Use the following data as an example:</p>
|
||||
<pre>
|
||||
@ -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..");'
|
||||
|
||||
```
|
||||
|
||||
@ -123,7 +123,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 => {
|
||||
|
@ -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.'');'
|
||||
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'']].");'
|
||||
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.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"]].");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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'');'
|
||||
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.deepEqual(res12, exp12, "crossProduct([1, 2, 3], [4, 5, 6]) must return [-3, 6, -3].");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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'');'
|
||||
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.'');'
|
||||
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.'');'
|
||||
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([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");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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");'
|
||||
|
||||
```
|
||||
|
||||
@ -91,7 +91,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(' ');
|
||||
|
@ -7,16 +7,16 @@ challengeType: 5
|
||||
## Description
|
||||
<section id='description'>
|
||||
<p>
|
||||
In strict
|
||||
In strict
|
||||
<a href="https://en.wikipedia.org/wiki/Functional programming" title="wp: functional programming">functional programming</a> and
|
||||
the <a href="https://en.wikipedia.org/wiki/lambda calculus" title="wp: lambda calculus">lambda calculus</a>,
|
||||
functions (lambda expressions) don't have state and are only allowed to refer to arguments of enclosing functions.
|
||||
the <a href="https://en.wikipedia.org/wiki/lambda calculus" title="wp: lambda calculus">lambda calculus</a>,
|
||||
functions (lambda expressions) don't have state and are only allowed to refer to arguments of enclosing functions.
|
||||
This rules out the usual definition of a recursive function wherein a function is associated with the state of a variable and this variable's state is used in the body of the function.
|
||||
</p>
|
||||
<p>
|
||||
The <a href="http://mvanier.livejournal.com/2897.html">Y combinator</a> is itself a stateless function that,
|
||||
when applied to another stateless function, returns a recursive version of the function. The Y combinator is
|
||||
the simplest of the class of such functions, called
|
||||
the simplest of the class of such functions, called
|
||||
<a href="https://en.wikipedia.org/wiki/Fixed-point combinator" title="wp: fixed-point combinator">fixed-point combinators</a>.
|
||||
</p>
|
||||
Task:
|
||||
@ -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.");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -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");'
|
||||
|
||||
```
|
||||
|
||||
|
@ -6,11 +6,11 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
A ''zig-zag'' array is a square arrangement of the first
|
||||
A "zig-zag" array is a square arrangement of the first
|
||||
$N^2$ integers, where the
|
||||
numbers increase sequentially as you zig-zag along the array's
|
||||
<a href="https://en.wiktionary.org/wiki/antidiagonal">anti-diagonals</a>.
|
||||
For example, given '''5''', produce this array:
|
||||
For example, given "'5"', 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'');'
|
||||
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]]'');'
|
||||
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.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");'
|
||||
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user