trackler 2.2.0.0 → 2.2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/problem-specifications/CONTRIBUTING.md +1 -1
- data/tracks/bash/.travis.yml +1 -1
- data/tracks/bash/config.json +30 -3
- data/tracks/c/README.md +1 -1
- data/tracks/c/config.json +131 -39
- data/tracks/ceylon/README.md +6 -6
- data/tracks/ceylon/config.json +21 -3
- data/tracks/chapel/.travis.yml +1 -1
- data/tracks/clojurescript/.travis.yml +1 -1
- data/tracks/clojurescript/README.md +6 -6
- data/tracks/clojurescript/exercises/.keep +0 -0
- data/tracks/coffeescript/.travis.yml +1 -1
- data/tracks/coldfusion/.travis.yml +1 -1
- data/tracks/coq/.travis.yml +1 -1
- data/tracks/cpp/CMakeLists.txt +1 -0
- data/tracks/cpp/README.md +1 -1
- data/tracks/cpp/config.json +8 -0
- data/tracks/cpp/exercises/atbash-cipher/CMakeLists.txt +52 -0
- data/tracks/cpp/exercises/atbash-cipher/atbash_cipher_test.cpp +68 -0
- data/tracks/cpp/exercises/atbash-cipher/example.cpp +54 -0
- data/tracks/cpp/exercises/atbash-cipher/example.h +13 -0
- data/tracks/csharp/config.json +315 -6
- data/tracks/d/.travis.yml +1 -1
- data/tracks/dart/README.md +2 -2
- data/tracks/dart/config.json +21 -3
- data/tracks/delphi/README.md +1 -1
- data/tracks/delphi/config.json +83 -1
- data/tracks/ecmascript/config.json +10 -0
- data/tracks/ecmascript/exercises/accumulate/accumulate.spec.js +3 -9
- data/tracks/ecmascript/exercises/acronym/acronym.spec.js +2 -2
- data/tracks/ecmascript/exercises/all-your-base/all-your-base.spec.js +131 -133
- data/tracks/ecmascript/exercises/all-your-base/example.js +1 -3
- data/tracks/ecmascript/exercises/allergies/allergies.spec.js +8 -10
- data/tracks/ecmascript/exercises/allergies/example.js +3 -5
- data/tracks/ecmascript/exercises/alphametics/alphametics.spec.js +61 -63
- data/tracks/ecmascript/exercises/alphametics/example.js +99 -99
- data/tracks/ecmascript/exercises/anagram/anagram.spec.js +35 -37
- data/tracks/ecmascript/exercises/anagram/example.js +1 -3
- data/tracks/ecmascript/exercises/atbash-cipher/atbash-cipher.spec.js +1 -3
- data/tracks/ecmascript/exercises/atbash-cipher/example.js +3 -3
- data/tracks/ecmascript/exercises/beer-song/beer-song.spec.js +0 -2
- data/tracks/ecmascript/exercises/beer-song/example.js +9 -9
- data/tracks/ecmascript/exercises/binary/binary.spec.js +1 -2
- data/tracks/ecmascript/exercises/binary/example.js +3 -3
- data/tracks/ecmascript/exercises/binary-search/binary-search.spec.js +1 -3
- data/tracks/ecmascript/exercises/binary-search-tree/binary-search-tree.spec.js +13 -15
- data/tracks/ecmascript/exercises/binary-search-tree/example.js +2 -2
- data/tracks/ecmascript/exercises/bob/bob.spec.js +1 -3
- data/tracks/ecmascript/exercises/bob/example.js +3 -3
- data/tracks/ecmascript/exercises/bracket-push/example.js +2 -2
- data/tracks/ecmascript/exercises/circular-buffer/circular-buffer.spec.js +10 -12
- data/tracks/ecmascript/exercises/circular-buffer/example.js +12 -11
- data/tracks/ecmascript/exercises/clock/clock.spec.js +0 -8
- data/tracks/ecmascript/exercises/clock/example.js +11 -11
- data/tracks/ecmascript/exercises/connect/connect.spec.js +75 -77
- data/tracks/ecmascript/exercises/connect/example.js +27 -29
- data/tracks/ecmascript/exercises/crypto-square/crypto-square.spec.js +11 -11
- data/tracks/ecmascript/exercises/crypto-square/example.js +11 -10
- data/tracks/ecmascript/exercises/custom-set/custom-set.spec.js +2 -4
- data/tracks/ecmascript/exercises/custom-set/example.js +1 -1
- data/tracks/ecmascript/exercises/diamond/diamond.spec.js +20 -21
- data/tracks/ecmascript/exercises/diamond/example.js +12 -13
- data/tracks/ecmascript/exercises/difference-of-squares/difference-of-squares.spec.js +0 -5
- data/tracks/ecmascript/exercises/diffie-hellman/diffie-hellman.spec.js +7 -28
- data/tracks/ecmascript/exercises/etl/etl.spec.js +36 -18
- data/tracks/ecmascript/exercises/etl/example.js +3 -3
- data/tracks/ecmascript/exercises/flatten-array/example.js +1 -1
- data/tracks/ecmascript/exercises/flatten-array/flatten-array.spec.js +2 -3
- data/tracks/ecmascript/exercises/food-chain/example.js +12 -12
- data/tracks/ecmascript/exercises/food-chain/food-chain.spec.js +0 -1
- data/tracks/ecmascript/exercises/gigasecond/example.js +1 -1
- data/tracks/ecmascript/exercises/gigasecond/gigasecond.spec.js +0 -1
- data/tracks/ecmascript/exercises/grade-school/grade-school.spec.js +18 -19
- data/tracks/ecmascript/exercises/grains/grains.spec.js +0 -1
- data/tracks/ecmascript/exercises/hamming/example.js +3 -3
- data/tracks/ecmascript/exercises/hamming/hamming.spec.js +5 -6
- data/tracks/ecmascript/exercises/hello-world/example.js +1 -1
- data/tracks/ecmascript/exercises/hello-world/hello-world.spec.js +1 -1
- data/tracks/ecmascript/exercises/hexadecimal/example.js +2 -2
- data/tracks/ecmascript/exercises/hexadecimal/hexadecimal.spec.js +9 -11
- data/tracks/ecmascript/exercises/isogram/isogram.spec.js +22 -23
- data/tracks/ecmascript/exercises/kindergarten-garden/example.js +7 -7
- data/tracks/ecmascript/exercises/kindergarten-garden/kindergarten-garden.spec.js +0 -5
- data/tracks/ecmascript/exercises/largest-series-product/example.js +4 -8
- data/tracks/ecmascript/exercises/largest-series-product/largest-series-product.spec.js +5 -7
- data/tracks/ecmascript/exercises/leap/leap.spec.js +4 -6
- data/tracks/ecmascript/exercises/linked-list/example.js +2 -2
- data/tracks/ecmascript/exercises/list-ops/example.js +19 -19
- data/tracks/ecmascript/exercises/list-ops/list-ops.spec.js +2 -18
- data/tracks/ecmascript/exercises/luhn/example.js +1 -1
- data/tracks/ecmascript/exercises/luhn/luhn.spec.js +1 -3
- data/tracks/ecmascript/exercises/matrix/example.js +2 -4
- data/tracks/ecmascript/exercises/matrix/matrix.spec.js +0 -2
- data/tracks/ecmascript/exercises/meetup/example.js +12 -15
- data/tracks/ecmascript/exercises/meetup/meetup.spec.js +0 -2
- data/tracks/ecmascript/exercises/minesweeper/example.js +60 -0
- data/tracks/ecmascript/exercises/minesweeper/minesweeper.spec.js +174 -0
- data/tracks/ecmascript/exercises/minesweeper/package.json +69 -0
- data/tracks/ecmascript/exercises/nth-prime/example.js +3 -2
- data/tracks/ecmascript/exercises/nth-prime/nth-prime.spec.js +0 -1
- data/tracks/ecmascript/exercises/ocr-numbers/example.js +3 -3
- data/tracks/ecmascript/exercises/ocr-numbers/ocr-numbers.spec.js +16 -18
- data/tracks/ecmascript/exercises/octal/example.js +1 -1
- data/tracks/ecmascript/exercises/octal/octal.spec.js +0 -2
- data/tracks/ecmascript/exercises/palindrome-products/example.js +14 -11
- data/tracks/ecmascript/exercises/palindrome-products/palindrome-products.spec.js +15 -18
- data/tracks/ecmascript/exercises/pangram/example.js +6 -5
- data/tracks/ecmascript/exercises/pangram/pangram.spec.js +10 -12
- data/tracks/ecmascript/exercises/pascals-triangle/example.js +2 -2
- data/tracks/ecmascript/exercises/pascals-triangle/pascals-triangle.spec.js +6 -8
- data/tracks/ecmascript/exercises/perfect-numbers/example.js +3 -5
- data/tracks/ecmascript/exercises/perfect-numbers/perfect-numbers.spec.js +0 -10
- data/tracks/ecmascript/exercises/phone-number/example.js +2 -2
- data/tracks/ecmascript/exercises/phone-number/phone-number.spec.js +0 -2
- data/tracks/ecmascript/exercises/pig-latin/example.js +4 -4
- data/tracks/ecmascript/exercises/pig-latin/pig-latin.spec.js +0 -1
- data/tracks/ecmascript/exercises/prime-factors/example.js +2 -2
- data/tracks/ecmascript/exercises/prime-factors/prime-factors.spec.js +0 -2
- data/tracks/ecmascript/exercises/pythagorean-triplet/pythagorean-triplet.spec.js +3 -11
- data/tracks/ecmascript/exercises/queen-attack/example.js +17 -17
- data/tracks/ecmascript/exercises/queen-attack/queen-attack.spec.js +7 -8
- data/tracks/ecmascript/exercises/raindrops/example.js +1 -1
- data/tracks/ecmascript/exercises/raindrops/raindrops.spec.js +1 -2
- data/tracks/ecmascript/exercises/rna-transcription/example.js +5 -5
- data/tracks/ecmascript/exercises/rna-transcription/rna-transcription.spec.js +4 -5
- data/tracks/ecmascript/exercises/robot-name/example.js +6 -6
- data/tracks/ecmascript/exercises/robot-name/robot-name.spec.js +10 -11
- data/tracks/ecmascript/exercises/robot-simulator/example.js +1 -1
- data/tracks/ecmascript/exercises/robot-simulator/robot-simulator.spec.js +31 -32
- data/tracks/ecmascript/exercises/roman-numerals/example.js +16 -16
- data/tracks/ecmascript/exercises/saddle-points/saddle-points.spec.js +3 -3
- data/tracks/ecmascript/exercises/say/example.js +25 -25
- data/tracks/ecmascript/exercises/say/say.spec.js +2 -3
- data/tracks/ecmascript/exercises/scrabble-score/example.js +27 -9
- data/tracks/ecmascript/exercises/scrabble-score/scrabble-score.spec.js +6 -7
- data/tracks/ecmascript/exercises/secret-handshake/example.js +2 -3
- data/tracks/ecmascript/exercises/secret-handshake/secret-handshake.spec.js +3 -5
- data/tracks/ecmascript/exercises/series/series.spec.js +1 -3
- data/tracks/ecmascript/exercises/sieve/example.js +4 -3
- data/tracks/ecmascript/exercises/sieve/sieve.spec.js +0 -2
- data/tracks/ecmascript/exercises/simple-cipher/example.js +8 -9
- data/tracks/ecmascript/exercises/simple-cipher/simple-cipher.spec.js +4 -4
- data/tracks/ecmascript/exercises/space-age/example.js +1 -1
- data/tracks/ecmascript/exercises/space-age/space-age.spec.js +9 -11
- data/tracks/ecmascript/exercises/strain/example.js +4 -4
- data/tracks/ecmascript/exercises/strain/strain.spec.js +14 -16
- data/tracks/ecmascript/exercises/sum-of-multiples/example.js +4 -4
- data/tracks/ecmascript/exercises/triangle/triangle.spec.js +2 -4
- data/tracks/ecmascript/exercises/trinary/example.js +3 -3
- data/tracks/ecmascript/exercises/trinary/trinary.spec.js +0 -2
- data/tracks/ecmascript/exercises/two-bucket/example.js +30 -27
- data/tracks/ecmascript/exercises/two-bucket/two-bucket.spec.js +4 -8
- data/tracks/ecmascript/exercises/word-count/example.js +2 -2
- data/tracks/ecmascript/exercises/word-count/word-count.spec.js +2 -3
- data/tracks/ecmascript/exercises/wordy/example.js +6 -6
- data/tracks/ecmascript/exercises/wordy/wordy.spec.js +2 -4
- data/tracks/factor/config.json +15 -6
- data/tracks/fortran/.travis.yml +1 -1
- data/tracks/fsharp/config.json +312 -10
- data/tracks/go/README.md +1 -1
- data/tracks/go/config.json +523 -155
- data/tracks/haskell/README.md +2 -2
- data/tracks/haskell/config.json +256 -7
- data/tracks/haxe/.travis.yml +1 -1
- data/tracks/haxe/Makefile +2 -2
- data/tracks/haxe/config.json +8 -5
- data/tracks/java/CONTRIBUTING.md +2 -2
- data/tracks/java/config.json +277 -17
- data/tracks/java/exercises/rotational-cipher/build.gradle +17 -0
- data/tracks/java/exercises/rotational-cipher/src/example/java/RotationalCipher.java +37 -0
- data/tracks/java/exercises/rotational-cipher/src/main/java/.keep +0 -0
- data/tracks/java/exercises/rotational-cipher/src/test/java/RotationalCipherTest.java +81 -0
- data/tracks/java/exercises/settings.gradle +1 -0
- data/tracks/java/exercises/twelve-days/src/main/java/TwelveDays.java +4 -0
- data/tracks/julia/.travis.yml +1 -1
- data/tracks/julia/README.md +1 -1
- data/tracks/kotlin/README.md +2 -2
- data/tracks/kotlin/exercises/hello-world/TUTORIAL.md +3 -3
- data/tracks/lisp/config.json +97 -3
- data/tracks/lisp/exercises/pascals-triangle/example.lisp +21 -0
- data/tracks/lisp/exercises/pascals-triangle/pascal.lisp +7 -0
- data/tracks/lisp/exercises/pascals-triangle/pascals-triangle-test.lisp +34 -0
- data/tracks/lua/.travis.yml +1 -1
- data/tracks/lua/README.md +1 -1
- data/tracks/mips/.travis.yml +1 -1
- data/tracks/mips/config.json +56 -17
- data/tracks/nasm/.travis.yml +1 -1
- data/tracks/nim/.travis.yml +1 -1
- data/tracks/ocaml/README.md +3 -3
- data/tracks/ocaml/config.json +130 -4
- data/tracks/perl5/docs/TESTS.md +40 -26
- data/tracks/plsql/.travis.yml +1 -1
- data/tracks/plsql/config.json +40 -13
- data/tracks/pony/.travis.yml +1 -1
- data/tracks/pony/bin/install-deps +4 -3
- data/tracks/prolog/.travis.yml +1 -1
- data/tracks/r/README.md +5 -5
- data/tracks/r/config.json +102 -30
- data/tracks/rust/.travis.yml +1 -1
- data/tracks/rust/config.json +172 -4
- data/tracks/rust/docs/EXERCISE_README_INSERT.md +1 -1
- data/tracks/sml/config.json +26 -3
- data/tracks/vimscript/config.json +60 -3
- metadata +16 -1
@@ -1,33 +1,32 @@
|
|
1
|
-
import Diamond from './diamond.js'
|
1
|
+
import Diamond from './diamond.js';
|
2
2
|
|
3
3
|
describe('Make diamond function', () => {
|
4
|
+
const diamond = new Diamond();
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
test('test letter A', function() {
|
8
|
-
const result = "A\n";
|
6
|
+
test('test letter A', () => {
|
7
|
+
const result = 'A\n';
|
9
8
|
expect(diamond.makeDiamond('A')).toEqual(result);
|
10
9
|
});
|
11
10
|
|
12
|
-
xtest('test letter C',
|
13
|
-
const result = [
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
xtest('test letter C', () => {
|
12
|
+
const result = `${[' A ',
|
13
|
+
' B B ',
|
14
|
+
'C C',
|
15
|
+
' B B ',
|
16
|
+
' A '].join('\n')}\n`;
|
18
17
|
expect(diamond.makeDiamond('C')).toEqual(result);
|
19
18
|
});
|
20
19
|
|
21
|
-
xtest('test letter E',
|
22
|
-
const result = [
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
20
|
+
xtest('test letter E', () => {
|
21
|
+
const result = `${[' A ',
|
22
|
+
' B B ',
|
23
|
+
' C C ',
|
24
|
+
' D D ',
|
25
|
+
'E E',
|
26
|
+
' D D ',
|
27
|
+
' C C ',
|
28
|
+
' B B ',
|
29
|
+
' A '].join('\n')}\n`;
|
31
30
|
expect(diamond.makeDiamond('E')).toEqual(result);
|
32
31
|
});
|
33
32
|
});
|
@@ -1,12 +1,12 @@
|
|
1
1
|
export default class Diamond {
|
2
2
|
makeDiamond(input) {
|
3
|
-
const inputIndex =
|
4
|
-
|
5
|
-
|
6
|
-
for(i = 0; i <= inputIndex; i++){
|
3
|
+
const inputIndex = input.charCodeAt() - 65;
|
4
|
+
let output = '';
|
5
|
+
let i = 0;
|
6
|
+
for (i = 0; i <= inputIndex; i++) {
|
7
7
|
output += getLine(inputIndex, i);
|
8
8
|
}
|
9
|
-
for(i = inputIndex - 1; i >= 0; i--){
|
9
|
+
for (i = inputIndex - 1; i >= 0; i--) {
|
10
10
|
output += getLine(inputIndex, i);
|
11
11
|
}
|
12
12
|
return output;
|
@@ -14,19 +14,18 @@ export default class Diamond {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
function getLine(inputIndex, index) {
|
17
|
-
|
18
|
-
return spaceTimes(difference) + printAlphabets(index) + spaceTimes(difference)
|
17
|
+
const difference = inputIndex - index;
|
18
|
+
return `${spaceTimes(difference) + printAlphabets(index) + spaceTimes(difference)}\n`;
|
19
19
|
}
|
20
20
|
|
21
21
|
function printAlphabets(index) {
|
22
|
-
|
23
|
-
if(index === 0){
|
24
|
-
return
|
25
|
-
} else {
|
26
|
-
return String.fromCharCode(character) + spaceTimes((index - 1) * 2 + 1) + String.fromCharCode(character);
|
22
|
+
const character = 65 + index;
|
23
|
+
if (index === 0) {
|
24
|
+
return 'A';
|
27
25
|
}
|
26
|
+
return String.fromCharCode(character) + spaceTimes((index - 1) * 2 + 1) + String.fromCharCode(character);
|
28
27
|
}
|
29
28
|
|
30
29
|
function spaceTimes(times) {
|
31
|
-
return
|
30
|
+
return ' '.repeat(times);
|
32
31
|
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import Squares from './difference-of-squares';
|
2
2
|
|
3
3
|
describe('Squares', () => {
|
4
|
-
|
5
4
|
describe('up to 5', () => {
|
6
5
|
const squares = new Squares(5);
|
7
6
|
|
@@ -16,7 +15,6 @@ describe('Squares', () => {
|
|
16
15
|
xtest('gets the difference', () => {
|
17
16
|
expect(squares.difference).toBe(170);
|
18
17
|
});
|
19
|
-
|
20
18
|
});
|
21
19
|
|
22
20
|
describe('up to 10', () => {
|
@@ -33,7 +31,6 @@ describe('Squares', () => {
|
|
33
31
|
xtest('gets the difference', () => {
|
34
32
|
expect(squares.difference).toBe(2640);
|
35
33
|
});
|
36
|
-
|
37
34
|
});
|
38
35
|
|
39
36
|
describe('up to 100', () => {
|
@@ -50,7 +47,5 @@ describe('Squares', () => {
|
|
50
47
|
xtest('gets the difference', () => {
|
51
48
|
expect(squares.difference).toBe(25164150);
|
52
49
|
});
|
53
|
-
|
54
50
|
});
|
55
|
-
|
56
51
|
});
|
@@ -12,75 +12,56 @@ describe('diffie-hellman', () => {
|
|
12
12
|
const bobPublicKey = 19;
|
13
13
|
|
14
14
|
test('throws an error if the constructor arguments are out of range', () => {
|
15
|
-
|
16
15
|
expect(() => {
|
17
|
-
new DiffieHellman(0, 9999)
|
16
|
+
new DiffieHellman(0, 9999);
|
18
17
|
}).toThrow();
|
19
|
-
|
20
18
|
});
|
21
19
|
|
22
20
|
xtest('throws an error if the constructor arguments are not prime', () => {
|
23
|
-
|
24
21
|
expect(() => {
|
25
|
-
new DiffieHellman(10, 13)
|
22
|
+
new DiffieHellman(10, 13);
|
26
23
|
}).toThrow();
|
27
|
-
|
28
24
|
});
|
29
25
|
|
30
26
|
xtest('throws an error if private key is negative', () => {
|
31
|
-
|
32
27
|
expect(() => {
|
33
|
-
diffieHellman.getPublicKeyFromPrivateKey(-1)
|
28
|
+
diffieHellman.getPublicKeyFromPrivateKey(-1);
|
34
29
|
}).toThrow();
|
35
|
-
|
36
30
|
});
|
37
31
|
|
38
32
|
xtest('throws an error if private key is zero', () => {
|
39
|
-
|
40
33
|
expect(() => {
|
41
|
-
diffieHellman.getPublicKeyFromPrivateKey(0)
|
34
|
+
diffieHellman.getPublicKeyFromPrivateKey(0);
|
42
35
|
}).toThrow();
|
43
|
-
|
44
36
|
});
|
45
37
|
|
46
38
|
xtest('throws an error if private key is one', () => {
|
47
|
-
|
48
39
|
expect(() => {
|
49
|
-
diffieHellman.getPublicKeyFromPrivateKey(1)
|
40
|
+
diffieHellman.getPublicKeyFromPrivateKey(1);
|
50
41
|
}).toThrow();
|
51
|
-
|
52
42
|
});
|
53
43
|
|
54
44
|
xtest('throws an error if private key equals the modulus parameter p', () => {
|
55
|
-
|
56
45
|
expect(() => {
|
57
|
-
diffieHellman.getPublicKeyFromPrivateKey(p)
|
46
|
+
diffieHellman.getPublicKeyFromPrivateKey(p);
|
58
47
|
}).toThrow();
|
59
|
-
|
60
48
|
});
|
61
49
|
|
62
50
|
xtest('throws an error if private key is greater than the modulus parameter p', () => {
|
63
|
-
|
64
51
|
expect(() => {
|
65
|
-
diffieHellman.getPublicKeyFromPrivateKey(p + 1)
|
52
|
+
diffieHellman.getPublicKeyFromPrivateKey(p + 1);
|
66
53
|
}).toThrow();
|
67
|
-
|
68
54
|
});
|
69
55
|
|
70
56
|
xtest('when given a private key, returns the correct public one', () => {
|
71
|
-
|
72
57
|
expect(diffieHellman.getPublicKeyFromPrivateKey(alicePrivateKey)).toEqual(alicePublicKey);
|
73
|
-
|
74
58
|
});
|
75
59
|
|
76
60
|
xtest('when given a different private key, returns the correct public one', () => {
|
77
|
-
|
78
61
|
expect(diffieHellman.getPublicKeyFromPrivateKey(bobPrivateKey)).toEqual(bobPublicKey);
|
79
|
-
|
80
62
|
});
|
81
63
|
|
82
64
|
xtest('can generate a shared secret from our private key and their public key', () => {
|
83
|
-
|
84
65
|
const sharedSecret = 2;
|
85
66
|
|
86
67
|
expect(diffieHellman.getSharedSecret(alicePrivateKey, bobPublicKey))
|
@@ -88,7 +69,5 @@ describe('diffie-hellman', () => {
|
|
88
69
|
|
89
70
|
expect(diffieHellman.getSharedSecret(bobPrivateKey, alicePublicKey))
|
90
71
|
.toEqual(sharedSecret);
|
91
|
-
|
92
72
|
});
|
93
|
-
|
94
73
|
});
|
@@ -1,23 +1,22 @@
|
|
1
1
|
import transform from './etl';
|
2
2
|
|
3
3
|
describe('Transform', () => {
|
4
|
-
|
5
4
|
test('transforms one value', () => {
|
6
|
-
const old = { 1: [
|
5
|
+
const old = { 1: ['A'] };
|
7
6
|
const expected = { a: 1 };
|
8
7
|
|
9
8
|
expect(transform(old)).toEqual(expected);
|
10
9
|
});
|
11
10
|
|
12
11
|
xtest('transforms more values', () => {
|
13
|
-
const old = { 1: [
|
12
|
+
const old = { 1: ['A', 'E', 'I', 'O', 'U'] };
|
14
13
|
const expected = { a: 1, e: 1, i: 1, o: 1, u: 1 };
|
15
14
|
|
16
15
|
expect(transform(old)).toEqual(expected);
|
17
16
|
});
|
18
17
|
|
19
18
|
xtest('transforms more keys', () => {
|
20
|
-
const old = { 1: [
|
19
|
+
const old = { 1: ['A', 'E'], 2: ['D', 'G'] };
|
21
20
|
const expected = { a: 1, e: 1, d: 2, g: 2 };
|
22
21
|
|
23
22
|
expect(transform(old)).toEqual(expected);
|
@@ -25,24 +24,43 @@ describe('Transform', () => {
|
|
25
24
|
|
26
25
|
xtest('transforms a full dataset', () => {
|
27
26
|
const old = {
|
28
|
-
1: [
|
29
|
-
2: [
|
30
|
-
3: [
|
31
|
-
4: [
|
32
|
-
5: [
|
33
|
-
8: [
|
34
|
-
10: [
|
27
|
+
1: ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'],
|
28
|
+
2: ['D', 'G'],
|
29
|
+
3: ['B', 'C', 'M', 'P'],
|
30
|
+
4: ['F', 'H', 'V', 'W', 'Y'],
|
31
|
+
5: ['K'],
|
32
|
+
8: ['J', 'X'],
|
33
|
+
10: ['Q', 'Z'],
|
35
34
|
};
|
36
35
|
const expected = {
|
37
|
-
a: 1,
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
a: 1,
|
37
|
+
b: 3,
|
38
|
+
c: 3,
|
39
|
+
d: 2,
|
40
|
+
e: 1,
|
41
|
+
f: 4,
|
42
|
+
g: 2,
|
43
|
+
h: 4,
|
44
|
+
i: 1,
|
45
|
+
j: 8,
|
46
|
+
k: 5,
|
47
|
+
l: 1,
|
48
|
+
m: 3,
|
49
|
+
n: 1,
|
50
|
+
o: 1,
|
51
|
+
p: 3,
|
52
|
+
q: 10,
|
53
|
+
r: 1,
|
54
|
+
s: 1,
|
55
|
+
t: 1,
|
56
|
+
u: 1,
|
57
|
+
v: 4,
|
58
|
+
w: 4,
|
59
|
+
x: 8,
|
60
|
+
y: 4,
|
61
|
+
z: 10,
|
43
62
|
};
|
44
63
|
|
45
64
|
expect(transform(old)).toEqual(expected);
|
46
65
|
});
|
47
|
-
|
48
66
|
});
|
@@ -1,11 +1,11 @@
|
|
1
1
|
function transform(input) {
|
2
|
-
|
2
|
+
const output = {};
|
3
3
|
|
4
4
|
Object.keys(input).forEach((key) => {
|
5
|
-
|
5
|
+
const items = input[key] || [];
|
6
6
|
|
7
7
|
items.forEach((item) => {
|
8
|
-
|
8
|
+
const value = item.toLowerCase();
|
9
9
|
output[value] = Number(key);
|
10
10
|
});
|
11
11
|
});
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import Flattener from
|
1
|
+
import Flattener from './flatten-array.js';
|
2
2
|
|
3
|
-
describe(
|
3
|
+
describe('FlattenArray', () => {
|
4
4
|
const flattener = new Flattener();
|
5
5
|
test('flattens a nested list', () => {
|
6
6
|
expect(flattener.flatten([[]])).toEqual([]);
|
@@ -37,5 +37,4 @@ describe("FlattenArray", () => {
|
|
37
37
|
xtest('returns an empty list if all values in nested list are null', () => {
|
38
38
|
expect(flattener.flatten([null, [[[null]]], null, null, [[null, null], null], null])).toEqual([]);
|
39
39
|
});
|
40
|
-
|
41
40
|
});
|
@@ -9,24 +9,24 @@ export default class Song {
|
|
9
9
|
*/
|
10
10
|
verse(number) {
|
11
11
|
switch (number) {
|
12
|
-
|
12
|
+
case 1: return `I know an old lady who swallowed a fly.
|
13
13
|
I don't know why she swallowed the fly. Perhaps she'll die.
|
14
14
|
`;
|
15
15
|
|
16
|
-
|
16
|
+
case 2: return `I know an old lady who swallowed a spider.
|
17
17
|
It wriggled and jiggled and tickled inside her.
|
18
18
|
She swallowed the spider to catch the fly.
|
19
19
|
I don't know why she swallowed the fly. Perhaps she'll die.
|
20
20
|
`;
|
21
21
|
|
22
|
-
|
22
|
+
case 3: return `I know an old lady who swallowed a bird.
|
23
23
|
How absurd to swallow a bird!
|
24
24
|
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
|
25
25
|
She swallowed the spider to catch the fly.
|
26
26
|
I don't know why she swallowed the fly. Perhaps she'll die.
|
27
27
|
`;
|
28
28
|
|
29
|
-
|
29
|
+
case 4: return `I know an old lady who swallowed a cat.
|
30
30
|
Imagine that, to swallow a cat!
|
31
31
|
She swallowed the cat to catch the bird.
|
32
32
|
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
|
@@ -34,7 +34,7 @@ She swallowed the spider to catch the fly.
|
|
34
34
|
I don't know why she swallowed the fly. Perhaps she'll die.
|
35
35
|
`;
|
36
36
|
|
37
|
-
|
37
|
+
case 5: return `I know an old lady who swallowed a dog.
|
38
38
|
What a hog, to swallow a dog!
|
39
39
|
She swallowed the dog to catch the cat.
|
40
40
|
She swallowed the cat to catch the bird.
|
@@ -43,7 +43,7 @@ She swallowed the spider to catch the fly.
|
|
43
43
|
I don't know why she swallowed the fly. Perhaps she'll die.
|
44
44
|
`;
|
45
45
|
|
46
|
-
|
46
|
+
case 6: return `I know an old lady who swallowed a goat.
|
47
47
|
Just opened her throat and swallowed a goat!
|
48
48
|
She swallowed the goat to catch the dog.
|
49
49
|
She swallowed the dog to catch the cat.
|
@@ -51,9 +51,9 @@ She swallowed the cat to catch the bird.
|
|
51
51
|
She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.
|
52
52
|
She swallowed the spider to catch the fly.
|
53
53
|
I don't know why she swallowed the fly. Perhaps she'll die.
|
54
|
-
`;
|
54
|
+
`;
|
55
55
|
|
56
|
-
|
56
|
+
case 7: return `I know an old lady who swallowed a cow.
|
57
57
|
I don't know how she swallowed a cow!
|
58
58
|
She swallowed the cow to catch the goat.
|
59
59
|
She swallowed the goat to catch the dog.
|
@@ -64,7 +64,7 @@ She swallowed the spider to catch the fly.
|
|
64
64
|
I don't know why she swallowed the fly. Perhaps she'll die.
|
65
65
|
`;
|
66
66
|
|
67
|
-
|
67
|
+
case 8: return `I know an old lady who swallowed a horse.
|
68
68
|
She's dead, of course!
|
69
69
|
`;
|
70
70
|
}
|
@@ -81,11 +81,11 @@ She's dead, of course!
|
|
81
81
|
* portion of song corresponding to requested verse number range (inclusive).
|
82
82
|
*/
|
83
83
|
verses(first, last) {
|
84
|
-
|
85
|
-
|
84
|
+
const rangeLength = last - first + 1;
|
85
|
+
const sequence = Array.from({ length: rangeLength }, (v, k) => first + k); // integers from first to last
|
86
86
|
|
87
87
|
// build the final string
|
88
|
-
|
88
|
+
const str = sequence.map(x => this.verse(x));
|
89
89
|
str.push('');
|
90
90
|
return str.join('\n');
|
91
91
|
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import Gigasecond from './gigasecond';
|
2
2
|
|
3
3
|
describe('Gigasecond', () => {
|
4
|
-
|
5
4
|
test('tells a gigasecond anniversary since midnight', () => {
|
6
5
|
const gs = new Gigasecond(new Date(Date.UTC(2015, 8, 14)));
|
7
6
|
const expectedDate = new Date(Date.UTC(2047, 4, 23, 1, 46, 40));
|
@@ -14,33 +14,33 @@ describe('School', () => {
|
|
14
14
|
xtest('adding a student adds them to the roster for the given grade', () => {
|
15
15
|
school.add('Aimee', 2);
|
16
16
|
|
17
|
-
|
17
|
+
const expectedDb = { 2: ['Aimee'] };
|
18
18
|
expect(school.roster()).toEqual(expectedDb);
|
19
19
|
});
|
20
20
|
|
21
21
|
xtest('adding more students to the same grade adds them to the roster', () => {
|
22
|
-
school.add('Blair',2);
|
23
|
-
school.add('James',2);
|
24
|
-
school.add('Paul',2);
|
22
|
+
school.add('Blair', 2);
|
23
|
+
school.add('James', 2);
|
24
|
+
school.add('Paul', 2);
|
25
25
|
|
26
|
-
|
26
|
+
const expectedDb = { 2: ['Blair', 'James', 'Paul'] };
|
27
27
|
expect(school.roster()).toEqual(expectedDb);
|
28
28
|
});
|
29
29
|
|
30
30
|
xtest('adding students to different grades adds them to the roster', () => {
|
31
|
-
school.add('Chelsea',3);
|
32
|
-
school.add('Logan',7);
|
31
|
+
school.add('Chelsea', 3);
|
32
|
+
school.add('Logan', 7);
|
33
33
|
|
34
|
-
|
34
|
+
const expectedDb = { 3: ['Chelsea'], 7: ['Logan'] };
|
35
35
|
expect(school.roster()).toEqual(expectedDb);
|
36
36
|
});
|
37
37
|
|
38
38
|
xtest('grade returns the students in that grade in alphabetical order', () => {
|
39
|
-
school.add('Franklin',5);
|
40
|
-
school.add('Bradley',5);
|
41
|
-
school.add('Jeff',1);
|
39
|
+
school.add('Franklin', 5);
|
40
|
+
school.add('Bradley', 5);
|
41
|
+
school.add('Jeff', 1);
|
42
42
|
|
43
|
-
|
43
|
+
const expectedStudents = ['Bradley', 'Franklin'];
|
44
44
|
expect(school.grade(5)).toEqual(expectedStudents);
|
45
45
|
});
|
46
46
|
|
@@ -54,10 +54,10 @@ describe('School', () => {
|
|
54
54
|
school.add('Christopher', 4);
|
55
55
|
school.add('Kyle', 3);
|
56
56
|
|
57
|
-
|
58
|
-
3
|
59
|
-
4
|
60
|
-
6
|
57
|
+
const expectedSortedStudents = {
|
58
|
+
3: ['Kyle'],
|
59
|
+
4: ['Christopher', 'Jennifer'],
|
60
|
+
6: ['Kareem'],
|
61
61
|
};
|
62
62
|
expect(school.roster()).toEqual(expectedSortedStudents);
|
63
63
|
});
|
@@ -66,15 +66,14 @@ describe('School', () => {
|
|
66
66
|
school.add('Aimee', 2);
|
67
67
|
const roster = school.roster();
|
68
68
|
roster[2].push('Oops.');
|
69
|
-
const expectedDb = { 2
|
69
|
+
const expectedDb = { 2: ['Aimee'] };
|
70
70
|
expect(school.roster()).toEqual(expectedDb);
|
71
71
|
});
|
72
72
|
|
73
73
|
xtest('roster cannot be modified outside of module using grade()', () => {
|
74
74
|
school.add('Aimee', 2);
|
75
75
|
school.grade(2).push('Oops.');
|
76
|
-
const expectedDb = { 2
|
76
|
+
const expectedDb = { 2: ['Aimee'] };
|
77
77
|
expect(school.roster()).toEqual(expectedDb);
|
78
78
|
});
|
79
|
-
|
80
79
|
});
|
@@ -2,15 +2,15 @@
|
|
2
2
|
class Hamming {
|
3
3
|
|
4
4
|
compute(strand1, strand2) {
|
5
|
-
|
6
|
-
|
5
|
+
const len1 = strand1.length;
|
6
|
+
const len2 = strand2.length;
|
7
7
|
if (len1 !== len2) {
|
8
8
|
throw new Error('DNA strands must be of equal length.');
|
9
9
|
}
|
10
10
|
|
11
11
|
let distance = 0;
|
12
12
|
let idx = -1;
|
13
|
-
|
13
|
+
const end = len1; // there could be len2, they're equal
|
14
14
|
while (++idx < end) {
|
15
15
|
if (strand1[idx] !== strand2[idx]) {
|
16
16
|
distance++;
|
@@ -1,22 +1,22 @@
|
|
1
1
|
import Hamming from './hamming';
|
2
2
|
|
3
3
|
describe('Hamming', () => {
|
4
|
-
|
4
|
+
const hamming = new Hamming();
|
5
5
|
|
6
6
|
test('no difference between identical strands', () => {
|
7
7
|
expect(hamming.compute('A', 'A')).toEqual(0);
|
8
8
|
});
|
9
9
|
|
10
10
|
xtest('complete hamming distance for single nucleotide strand', () => {
|
11
|
-
expect(hamming.compute('A','G')).toEqual(1);
|
11
|
+
expect(hamming.compute('A', 'G')).toEqual(1);
|
12
12
|
});
|
13
13
|
|
14
14
|
xtest('complete hamming distance for small strand', () => {
|
15
|
-
expect(hamming.compute('AG','CT')).toEqual(2);
|
15
|
+
expect(hamming.compute('AG', 'CT')).toEqual(2);
|
16
16
|
});
|
17
17
|
|
18
18
|
xtest('small hamming distance', () => {
|
19
|
-
expect(hamming.compute('AT','CT')).toEqual(1);
|
19
|
+
expect(hamming.compute('AT', 'CT')).toEqual(1);
|
20
20
|
});
|
21
21
|
|
22
22
|
xtest('small hamming distance in longer strand', () => {
|
@@ -33,8 +33,7 @@ describe('Hamming', () => {
|
|
33
33
|
|
34
34
|
xtest('throws error when strands are not equal length', () => {
|
35
35
|
expect(() => hamming.compute('GGACGGATTCTG', 'AGGAC')).toThrow(
|
36
|
-
new Error('DNA strands must be of equal length.')
|
36
|
+
new Error('DNA strands must be of equal length.'),
|
37
37
|
);
|
38
38
|
});
|
39
|
-
|
40
39
|
});
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export default function(hex) {
|
1
|
+
export default function (hex) {
|
2
2
|
this.hex = hex;
|
3
3
|
|
4
4
|
this.toDecimal = () => {
|
@@ -8,6 +8,6 @@ export default function(hex) {
|
|
8
8
|
if (/[^0-9a-fA-F]/.exec(hexCharacters[i])) { return 0; }
|
9
9
|
}
|
10
10
|
|
11
|
-
return parseInt(this.hex,16);
|
11
|
+
return parseInt(this.hex, 16);
|
12
12
|
};
|
13
13
|
}
|