8000 remove timer and simon · M-Munk/javascript-exercises@834d78b · GitHub
[go: up one dir, main page]

Skip to content

Commit 834d78b

Browse files
committed
remove timer and simon
1 parent 14cc7d4 commit 834d78b

File tree

2,928 files changed

+303453
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,928 files changed

+303453
-313
lines changed

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
"extends": "airbnb-base",
3+
"plugins": [
4+
"import"
5+
]
6+
};

book_titles/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

book_titles/bookTitles.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

book_titles/bookTitles.spec.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

caesar/caesar.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1-
var caesar = function() {
1+
const caesar = function(string, shift) {
2+
return string
3+
.split("")
4+
.map(char => shiftChar(char, shift))
5+
.join("");
6+
};
27

3-
}
8+
const codeSet = code => (code < 97 ? 65 : 97);
49

5-
module.exports = caesar
10+
const mod = (n, m) => (n % m + m) % m;
11+
12+
const shiftChar = (char, shift) => {
13+
const code = char.charCodeAt();
14+
15+
if ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) {
16+
return String.fromCharCode(
17+
mod(code + shift - codeSet(code), 26) + codeSet(code)
18+
);
19+
}
20+
return char;
21+
};
22+
23+
module.exports = caesar;

caesar/caesar.spec.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
var caesar = require('./caesar')
1+
const caesar = require("./caesar");
22

3-
describe('caesar', function() {
4-
it('works with single letters', function() {
5-
expect(caesar('A', 1)).toEqual('B');
3+
describe("caesar", () => {
4+
it("works with single letters", () => {
5+
expect(caesar("A", 1)).toEqual("B");
66
});
7-
xit('works with words', function() {
8-
expect(caesar('Aaa', 1)).toEqual('Bbb');
7+
it("works with words", () => {
8+
expect(caesar("Aaa", 1)).toEqual("Bbb");
99
});
10-
xit('works with phrases', function() {
11-
expect(caesar('Hello, World!', 5)).toEqual('Mjqqt, Btwqi!');
10+
it("works with phrases", () => {
11+
expect(caesar("Hello, World!", 5)).toEqual("Mjqqt, Btwqi!");
1212
});
13-
xit('works with negative shift', function() {
14-
expect(caesar('Mjqqt, Btwqi!', -5)).toEqual('Hello, World!');
13+
it("works with negative shift", () => {
14+
expect(caesar("Mjqqt, Btwqi!", -5)).toEqual("Hello, World!");
1515
});
16-
xit('wraps', function() {
17-
expect(caesar('Z', 1)).toEqual('A');
16+
it("wraps", () => {
17+
expect(caesar("Z", 1)).toEqual("A");
1818
});
19-
xit('works with large shift factors', function() {
20-
expect(caesar('Hello, World!', 75)).toEqual('Ebiil, Tloia!');
19+
it("works with large shift factors", () => {
20+
expect(caesar("Hello, World!", 75)).toEqual("Ebiil, Tloia!");
2121
});
2222
});

calculator/calculator.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1-
function add () {
2-
1+
function add(a, b) {
2+
return a + b;
33
}
44

5-
function subtract () {
6-
5+
function subtract(a, b) {
6+
return a - b;
77
}
88

9-
function sum () {
10-
9+
function sum(array) {
10+
return array.reduce((current, total) => total + current, 0);
1111
}
1212

13-
function multiply () {
14-
13+
function multiply(array) {
14+
return array.reduce((current, total) => total * current, 1);
1515
}
1616

17-
function power() {
18-
17+
function power(a, b) {
18+
return Math.pow(a, b);
1919
}
2020

21-
function factorial() {
22-
21+
function factorial(n) {
22+
if (n == 0) return 0;
23+
let product = 1;
24+
for (let i = n; i > 0; i--) {
25+
product *= i;
26+
}
27+
return product;
2328
}
2429

2530
module.exports = {
26-
add,
27-
subtract,
28-
sum,
29-
multiply,
30-
power,
31-
factorial
32-
}
31+
add,
32+
subtract,
33+
sum,
34+
multiply,
35+
power,
36+
factorial
37+
};

node_modules/.bin/acorn

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/eslint

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/esparse

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/esvalidate

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/js-yaml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/mkdirp

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/rimraf

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/semver

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/which

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/acorn-jsx/LICENSE

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/acorn-jsx/README.md

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/acorn-jsx/index.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0