8000 Completed working on fundamentals part 4 exercises · SameerLags/javascript-exercises@e35ba9b · GitHub
[go: up one dir, main page]

Skip to content

Commit e35ba9b

Browse files
committed
Completed working on fundamentals part 4 exercises
1 parent 55e23a1 commit e35ba9b

File tree

13 files changed

+78
-44
lines changed

13 files changed

+78
-44
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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
const leapYears = function() {
2-
1+
const leapYears = function(year) {
2+
if(year%4==0){
3+
if(year%100==0){
4+
if(year%400==0) return true;
5+
return false;
6+
}
7+
return true;
8+
}
9+
return false;
310
}
411

512
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-
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
const removeFromArray = function() {
2-
1+
const removeFromArray = function(arr, ...args) {
2+
let arrReturn = []
3+
for(i=0; i<arr.length; i++){
4+
if(!args.includes(arr[i])){
5+
arrReturn.push(arr[i]);
6+
}
7+
}
8+
return arrReturn;
39
}
410

5-
module.exports = removeFromArray
11+
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-
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: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
const repeatString = function() {
2-
1+
const repeatString = function(stringToRepeat, timesToRepeat) {
2+
let repeatedString = ""
3+
if(timesToRepeat<0){
4+
return 'ERROR'
5+
}
6+
for(i=0; i<timesToRepeat; i++){
7+
repeatedString += stringToRepeat;
8+
}
9+
return(repeatedString)
310
}
411

5-
module.exports = repeatString
12+
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
const reverseString = function() {
2-
1+
const reverseString = function(stringToReverse) {
2+
let reversedString = ""
3+
for(i=stringToReverse.length-1; i>=0; i--){
4+
reversedString += stringToReverse[i];
5+
}
6+
return reversedString;
37
}
48

59
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

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: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
const sumAll = function() {
2-
1+
const sumAll = function(start, end) {
2+
let sum = 0;
3+
if(typeof(start) != "number" || typeof (end) != "number" ||
4+
start<0 || end<0){
5+
return 'ERROR';
6+
}
7+
if(start<=end){
8+
for(i=start; i<=end; i++) sum += i;
9+
}else{
10+
for(i=start; i>=end; i--) sum += i;
11+
}
12+
return sum;
313
}
414

5-
module.exports = sumAll
15+
module.exports = sumAll

sumAll/sumAll.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ describe('sumAll', function() {
44
it('sums numbers within the range', function() {
55
expect(sumAll(1, 4)).toEqual(10);
66
});
7-
xit('works with large numbers', function() {
7+
it('works with large numbers', function() {
88
expect(sumAll(1, 4000)).toEqual(8002000);
99
});
10-
xit('works with larger number first', function() {
10+
it('works with larger number first', function() {
1111
expect(sumAll(123, 1)).toEqual(7626);
1212
});
13-
xit('returns ERROR with negative numbers', function() {
13+
it('returns ERROR with negative numbers', function() {
1414
expect(sumAll(-10, 4)).toEqual('ERROR');
1515
});
16-
xit('returns ERROR with non-number parameters', function() {
16+
it('returns ERROR with non-number parameters', function() {
1717
expect(sumAll(10, "90")).toEqual('ERROR');
1818
});
19-
xit('returns ERROR with non-number parameters', function() {
19+
it('returns ERROR with non-number parameters', function() {
2020
expect(sumAll(10, [90, 1])).toEqual('ERROR');
2121
});
2222
});

tempConversion/tempConversion.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const ftoc = function() {
2-
1+
const ftoc = function(temp) {
2+
return Math.round(((temp-32)*5/9)*10)/10;
33
}
44

5-
const ctof = function() {
6-
5+
const ctof = function(temp) {
6+
return Math.round((temp*9/5 + 32)*10)/10;
77
}
88

99
module.exports = {

tempConversion/tempConversion.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ describe('ftoc', function() {
44
it('works', function() {
55
expect(ftoc(32)).toEqual(0);
66
});
7-
xit('rounds to 1 decimal', function() {
7+
it('rounds to 1 decimal', function() {
88
expect(ftoc(100)).toEqual(37.8);
99
});
10-
xit('works with negatives', function() {
10+
it('works with negatives', function() {
1111
expect(ftoc(-100)).toEqual(-73.3);
1212
});
1313
});
1414

1515
describe('ctof', function() {
16-
xit('works', function() {
16+
it('works', function() {
1717
expect(ctof(0)).toEqual(32);
1818
});
19-
xit('rounds to 1 decimal', function() {
19+
it('rounds to 1 decimal', function() {
2020
expect(ctof(73.2)).toEqual(163.8);
2121
});
22-
xit('works with negatives', function() {
22+
it('works with negatives', function() {
2323
expect(ctof(-10)).toEqual(14);
2424
});
2525
});

0 commit comments

Comments
 (0)
0