8000 update solutions · M-Munk/javascript-exercises@0f6f7b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f6f7b1

Browse files
committed
update solutions
1 parent 1852eca commit 0f6f7b1

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

repeatString/repeatString.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
const repeatString = function() {
1+
const repeatString = function (string, num) {
2+
if (num >= 0) {
3+
let result = '';
4+
for (let i = 0; i < num; i++) {
5+
result += string;
6+
}
7+
return result;
8+
} else return 'ERROR';
9+
};
210

3-
}
4-
5-
module.exports = repeatString
11+
module.exports = repeatString;

repeatString/repeatString.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ 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
});
19-
xit('repeats the string a random amount of times', function () {
19+
it('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
@@ -27,7 +27,7 @@ describe('repeatString', function() {
2727
was randomaly generated. */
2828
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
2929
});
30-
xit('works with blank strings', function() {
30+
it('works with blank strings', function() {
3131
expect(repeatString('', 10)).toEqual('');
3232
});
3333
});

reverseString/reverseString.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
const reverseString = function() {
2-
1+
const reverseString = function(string) {
2+
let arr = Array.from(string);
3+
console.log(arr);
4+
let reversed = arr.reverse();
5+
return reversed.join('');
36
}
47

58
module.exports = reverseString

reverseString/reverseString.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ 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
})
15-
xit('works with blank strings', function() {
15+
it('works with blank strings', function() {
1616
expect(reverseString('')).toEqual('')
1717
})
1818
});

0 commit comments

Comments
 (0)
0