Skip to content

Commit d22762c

Browse files
committed
Testes Odin Project
1 parent 85a9d56 commit d22762c

File tree

14 files changed

+3821
-2206
lines changed

14 files changed

+3821
-2206
lines changed

01_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;

02_repeatString/repeatString.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
const repeatString = function() {
1+
const repeatString = function(theString, numberOfTimes) {
2+
if (numberOfTimes < 0) return 'ERROR';
3+
4+
let finalString = '';
5+
for (let i = 0; i < numberOfTimes; i++)
6+
finalString += theString;
27

8+
return finalString;
39
};
410

511
// Do not edit below this line

02_repeatString/repeatString.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ describe('repeatString', () => {
44
test('repeats the string', () => {
55
expect(repeatString('hey', 3)).toEqual('heyheyhey');
66
});
7-
test.skip('repeats the string many times', () => {
7+
test('repeats the string many times', () => {
88
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
99
});
10-
test.skip('repeats the string 1 times', () => {
10+
test('repeats the string 1 times', () => {
1111
expect(repeatString('hey', 1)).toEqual('hey');
1212
});
13-
test.skip('repeats the string 0 times', () => {
13+
test('repeats the string 0 times', () => {
1414
expect(repeatString('hey', 0)).toEqual('');
1515
});
16-
test.skip('returns ERROR with negative numbers', () => {
16+
test('returns ERROR with negative numbers', () => {
1717
expect(repeatString('hey', -1)).toEqual('ERROR');
1818
});
19-
test.skip('repeats the string a random amount of times', function () {
19+
test('repeats the string a random amount of times', function () {
2020
/*The number is generated by using Math.random to get a value from between
2121
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
2222
equals a number between 0 to 999 (this number will change everytime you run
@@ -31,7 +31,7 @@ describe('repeatString', () => {
3131
was randomly generated. */
3232
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
3333
});
34-
test.skip('works with blank strings', () => {
34+
test('works with blank strings', () => {
3535
expect(repeatString('', 10)).toEqual('');
3636
});
3737
});

03_reverseString/reverseString.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
const reverseString = function() {
1+
const reverseString = function(originalString) {
2+
let reversedString = originalString.split('').reverse().join('');
23

4+
return reversedString;
35
};
46

57
// Do not edit below this line

03_reverseString/reverseString.spec.js

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

8-
test.skip('reverses multiple words', () => {
8+
test('reverses multiple words', () => {
99
expect(reverseString('hello there')).toEqual('ereht olleh')
1010
})
1111

12-
test.skip('works with numbers and punctuation', () => {
12+
test('works with numbers and punctuation', () => {
1313
expect(reverseString('123! abc!')).toEqual('!cba !321')
1414
})
15-
test.skip('works with blank strings', () => {
15+
test('works with blank strings', () => {
1616
expect(reverseString('')).toEqual('')
1717
})
1818
});

04_removeFromArray/removeFromArray.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
const removeFromArray = function() {
1+
const removeFromArray = function(arrayOfElements, ...valuesToRemove) {
2+
let filteredArray = [...arrayOfElements];
23

4+
valuesToRemove.forEach(value => {
5+
filteredArray = filteredArray.filter(element => element !== value);
6+
})
7+
8+
return filteredArray;
39
};
410

511
// Do not edit below this line

04_removeFromArray/removeFromArray.spec.js

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

05_sumAll/sumAll.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
const sumAll = function() {
1+
const sumAll = function(n1, n2) {
2+
if (typeof n1 !== 'number' || typeof n2 !== 'number' || n1 < 0 || n2 < 0) return 'ERROR';
23

4+
let sum = 0;
5+
let biggerNumber = n1 > n2 ? n1 : n2;
6+
7+
for (let i = n1 > n2 ? n2 : n1; i <= biggerNumber; i++) {
8+
sum += i;
9+
}
10+
11+
return sum;
312
};
413

514
// Do not edit below this line

05_sumAll/sumAll.spec.js

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

06_leapYears/leapYears.js

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

8+
return false;
39
};
410

511
// Do not edit below this line

0 commit comments

Comments
 (0)