8000 Revert "remove class based exercises" · cvanert/javascript-exercises@829730f · GitHub
[go: up one dir, main page]

Skip to content

Commit 829730f

Browse files
committed
Revert "remove class based exercises"
This reverts commit 290e7f1.
1 parent 4d1f419 commit 829730f

File tree

18 files changed

+164
-67
lines changed

18 files changed

+164
-67
lines changed

book_titles/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The goal of this exercise is to introduce you to the concept of objects and classes. These are fundamental building blocks for OOP (Object Oriented Programming). You shouldn't need to write a ton of new code, in fact you can re-use your solution from the Simon Says exercise!
2+
3+
The key here will be rewriting certain bits of it to work within the class given to you.

book_titles/bookTitles.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class bookTitle {
2+
3+
}
4+
5+
module.exports = {
6+
bookTitle
7+
}
8+

book_titles/bookTitles.spec.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
var bookTitles = require ('./bookTitles.js');
2+
3+
describe('bookTitle', function() {
4+
5+
var book; // note the scope here, if you declare this inside beforeEach then the scope won't allow it to access the other specs
6+
7+
beforeEach(function() {
8+
book = new bookTitles.bookTitle(); // creates a new book instance before each test is run
9+
});
10+
11+
describe('title', function() {
12+
13+
it('should capitalize the first letter', function() {
14+
book.title = 'inferno';
15+
expect(book.title).toEqual('Inferno');
16+
});
17+
18+
it('should capitalize every word', function() {
19+
book.title = 'stuart little';
20+
expect(book.title).toEqual('Stuart Little');
21+
});
22+
23+
describe('should capitalize every word except...', function() {
24+
describe('articles', function() {
25+
it('does not capitalize "the"', function() {
26+
book.title = 'alexander the great';
27+
expect(book.title).toEqual('Alexander the Great');
28+
});
29+
30+
it('does not capitalize "a"', function() {
31+
book.title = 'to kill a mockingbird';
32+
expect(book.title).toEqual('To Kill a Mockingbird');
33+
});
34+
35+
it('does not capitalize "an"', function() {
36+
book.title = 'to eat an apple a day';
37+
expect(book.title).toEqual('To Eat an Apple a Day');
38+
});
39+
});
40+
41+
it('conjunctions', function() {
42+
book.title = 'war and peace';
43+
expect(book.title).toEqual('War and Peace');
44+
});
45+
46+
it('prepositions', function() {
47+
book.title = 'love in the time of cholera';
48+
expect(book.title).toEqual('Love in the Time of Cholera');
49+
});
50+
});
51+
52+
describe('should always capitalize...', function() {
53+
it('I', function() {
54+
book.title = 'what i wish i knew when i was 20';
55+
expect(book.title).toEqual('What I Wish I Knew When I Was 20');
56+
});
57+
58+
it('the first word', function() {
59+
book.title = 'the man in the iron mask';
60+
expect(book.title).toEqual('The Man in the Iron Mask');
61+
});
62+
});
63+
});
64+
});

helloWorld/helloWorld.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var helloWorld = function() {
2-
return 'Hello, World!'
2+
return ''
33
}
44

5-
module.exports = helloWorld
5+
module.exports = helloWorld

leapYears/leapYears.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
var leapYears = function(year) {
2-
if (year % 4 !== 0 || (year % 100 == 0 && year % 400 != 0)) {
3-
return false
4-
}
5-
return true
1+
var leapYears = function() {
2+
63
}
74

85
module.exports = leapYears

leapYears/leapYears.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ describe('leapYears', function() {
44
it('works with non century years', function() {
55
expect(leapYears(1996)).toEqual(true);
66
});
7-
it('works with non century years', function() {
7+
xit('works with non century years', function() {
88
expect(leapYears(1997)).toEqual(false);
99
});
10-
it('works with ridiculously futuristic non century years', function() {
10+
xit('works with ridiculously futuristic non century years', function() {
1111
expect(leapYears(34992)).toEqual(true);
1212
});
13-
it('works with century years', function() {
13+
xit('works with century years', function() {
1414
expect(leapYears(1900)).toEqual(false);
1515
});
16-
it('works with century years', function() {
16+
xit('works with century years', function() {
1717
expect(leapYears(1600)).toEqual(true);
1818
});
19-
it('works with century years', function() {
19+
xit('works with century years', function() {
2020
expect(leapYears(700)).toEqual(false);
2121
});
2222
});

removeFromArray/removeFromArray.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
var removeFromArray = function(array) {
2-
elementsToRemove = [...arguments]
3-
elementsToRemove.splice(0,1)
4-
elementsToRemove.forEach(element => {
5-
let index = array.indexOf(element)
6-
if (index > -1) {
7-
array.splice(index, 1)
8-
}
9-
})
10-
return array
1+
var removeFromArray = function() {
2+
113
}
124

135
module.exports = removeFromArray

removeFromArray/removeFromArray.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ describe('removeFromArray', function() {
44
it('removes a single value', function() {
55
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
66
});
7-
it('removes multiple values', function() {
7+
xit('removes multiple values', function() {
88
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
99
});
10-
it('ignores non present values', function() {
10+
xit('ignores non present values', function() {
1111
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
1212
});
13-
it('ignores non present values, but still works', function() {
13+
xit('ignores non present values, but still works', function() {
1414
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
1515
});
16-
it('can remove all values', function() {
16+
xit('can remove all values', function() {
1717
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
1818
});
19-
it('works with strings', function() {
19+
xit('works with strings', function() {
2020
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
2121
});
2222
});

repeatString/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Exercis 02 - repeatString
1+
# Exercise 02 - repeatString
22

33
Write a function that simply repeats the string a given number of times:
44

repeatString/repeatString.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
var repeatString = function(string, num) {
2-
if (num < 0) return 'ERROR'
3-
let returnValue = ''
4-
for(let i = 0; i < num; i++) {
5-
returnValue = returnValue + string
6-
}
7-
return returnValue
1+
var repeatString = function() {
2+
83
}
94

105
module.exports = repeatString

0 commit comments

Comments
 (0)
0