8000 Complete first 7 excercises · JoshAubrey/javascript-exercises@c1bc78b · GitHub
[go: up one dir, main page]

Skip to content

Commit c1bc78b

Browse files
committed
Complete first 7 excercises
1 parent 4f07675 commit c1bc78b

File tree

13 files changed

+93
-35
lines changed

13 files changed

+93
-35
lines changed

helloWorld/helloWorld.js

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

55
module.exports = helloWorld

leapYears/leapYears.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
const leapYears = function() {
1+
const leapYears = function(year) {
2+
3+
if (year % 4 == 0 && (year % 100 !== 0 || year % 400 == 0)) {
4+
return true
5+
}
6+
else {
7+
return false
8+
}
29

310
}
411

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-
xit('works with non century years', function() {
7+
it('works with non century years', function() {
88
expect(leapYears(1997)).toEqual(false);
99
});
10-
xit('works with ridiculously futuristic non century years', function() {
10+
it('works with ridiculously futuristic non century years', function() {
1111
expect(leapYears(34992)).toEqual(true);
1212
});
13-
xit('works with century years', function() {
13+
it('works with century years', function() {
1414
expect(leapYears(1900)).toEqual(false);
1515
});
16-
xit('works with century years', function() {
16+
it('works with century years', function() {
1717
expect(leapYears(1600)).toEqual(true);
1818
});
19-
xit('works with century years', function() {
19+
it('works with century years', function() {
2020
expect(leapYears(700)).toEqual(false);
2121
});
2222
});

removeFromArray/removeFromArray.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
const removeFromArray = function() {
1+
const removeFromArray = function(...arguments) {
2+
//spread operator used for arguments
3+
4+
//Create array from the first argument passed,
5+
//which is the array the other arguments will be removed from.
6+
const array = arguments[0]
7+
8+
//return the array items if they are NOT included in the other arguments.
9+
return array.filter(item => !arguments.includes(item))
210

311
}
412

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-
xit('removes multiple values', function() {
7+
it('removes multiple values', function() {
88
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
99
});
10-
xit('ignores non present values', function() {
10+
it('ignores non present values', function() {
1111
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
1212
});
13-
xit('ignores non present values, but still works', function() {
13+
it('ignores non present values, but still works', function() {
1414
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
1515
});
16-
xit('can remove all values', function() {
16+
it('can remove all values', function() {
1717
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
1818
});
19-
xit('works with strings', function() {
19+
it('works with strings', function() {
2020
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
2121
});
2222
});

repeatString/repeatString.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
const repeatString = function() {
1+
const repeatString = function(string, amount) {
2+
let result = ""
23

4+
if (amount < 0) {
5+
return 'ERROR'
6+
}
7+
8+
for (i=0; i<amount; i++) {
9+
result +=string
10+
}
11+
12+
return result
313
}
414

515
module.exports = repeatString

repeatString/repeatString.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ describe('repeatString', function() {
44
it('repeats the string', function() {
55
expect(repeatString('hey', 3)).toEqual('heyheyhey');
66
});
7-
xit('repeats the string many times', function() {
7+
it('repeats the string many times', function() {
88
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
99
});
10-
xit('repeats the string 1 times', function() {
10+
it('repeats the string 1 times', function() {
1111
expect(repeatString('hey', 1)).toEqual('hey');
1212
});
13-
xit('repeats the string 0 times', function() {
13+
it('repeats the string 0 times', function() {
1414
expect(repeatString('hey', 0)).toEqual('');
1515
});
16-
xit('returns ERROR with negative numbers', function() {
16+
it('returns ERROR with negative numbers', function() {
1717
expect(repeatString('hey', -1)).toEqual('ERROR');
1818
});
1919
});

reverseString/reverseString.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const reverseString = function() {
2-
1+
const reverseString = function(string) {
2+
return string.split("").reverse().join("")
33
}
44

55
module.exports = reverseString

reverseString/reverseString.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ describe('reverseString', function() {
55
expect(reverseString('hello')).toEqual('olleh');
66
});
77

< 68F6 /td>
8-
xit('reverses multiple words', function() {
8+
it('reverses multiple words', function() {
99
expect(reverseString('hello there')).toEqual('ereht olleh')
1010
})
1111

12-
xit('works with numbers and punctuation', function() {
12+
it('works with numbers and punctuation', function() {
1313
expect(reverseString('123! abc!')).toEqual('!cba !321')
1414
})
1515
});

sumAll/sumAll.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
const sumAll = function() {
1+
const sumAll = function(min, max) {
2+
let sum = 0
3+
4+
if (typeof min != "number" || typeof max != "number") {
5+
return 'ERROR'
6+
}
7+
8+
if (min < 0 || max < 0) {
9+
return 'ERROR'
10+
}
11+
12+
if (max < min) {
13+
const maxtemp = min
14+
min = max
15+
max = maxtemp
16+
}
17+
18+
for (let i=min; i<=max; i++) {
19+
sum += i
20+
}
21+
22+
return sum
223

324
}
425

0 commit comments

Comments
 (0)
0