mirror of
https://github.com/10h30/odin-javascript-exercises.git
synced 2026-06-05 15:09:09 +09:00
@@ -6,7 +6,7 @@ Write a function that simply repeats the string a given number of times:
|
||||
repeatString('hey', 3) // returns 'heyheyhey'
|
||||
```
|
||||
|
||||
You will notice in this exercise that there are multiple tests (see in file `repeatString.spec.js`). Only the first test is currently enabled. So after making sure that this first one passes, enable the others one by one by deleting the `.skip` from the `test.skip()` function.
|
||||
You will notice in this exercise that there are multiple tests (see in file `repeatString.spec.js`). Only the first test is currently enabled. So after making sure that this first one passes, enable the others one by one by deleting the `x` in front of the `it()` function.
|
||||
|
||||
|
||||
## Hints
|
||||
@@ -15,11 +15,4 @@ You will notice in this exercise that there are multiple tests (see in file `rep
|
||||
|
||||
- Create a variable to hold the string you're going to return, create a loop that repeats the given number of times and add the given string to the result on each loop.
|
||||
|
||||
- If running `npm test repeatString.spec.js` returns results similar to the below:
|
||||
|
||||
```
|
||||
Test Suites: 1 passed, 1 total
|
||||
Tests: 6 skipped, 1 passed, 7 total
|
||||
```
|
||||
|
||||
- Make sure you have enabled the rest of the tests (see above).
|
||||
- If running `jasmine repeatString.spec.js` raises `Temporarily disabled with xit` errors, make sure you have enabled the rest of the tests (see above).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const repeatString = function() {
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = repeatString;
|
||||
module.exports = repeatString
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
const repeatString = require('./repeatString')
|
||||
|
||||
describe('repeatString', () => {
|
||||
test('repeats the string', () => {
|
||||
describe('repeatString', function() {
|
||||
it('repeats the string', function() {
|
||||
expect(repeatString('hey', 3)).toEqual('heyheyhey');
|
||||
});
|
||||
test.skip('repeats the string many times', () => {
|
||||
xit('repeats the string many times', function() {
|
||||
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
|
||||
});
|
||||
test.skip('repeats the string 1 times', () => {
|
||||
xit('repeats the string 1 times', function() {
|
||||
expect(repeatString('hey', 1)).toEqual('hey');
|
||||
});
|
||||
test.skip('repeats the string 0 times', () => {
|
||||
xit('repeats the string 0 times', function() {
|
||||
expect(repeatString('hey', 0)).toEqual('');
|
||||
});
|
||||
test.skip('returns ERROR with negative numbers', () => {
|
||||
xit('returns ERROR with negative numbers', function() {
|
||||
expect(repeatString('hey', -1)).toEqual('ERROR');
|
||||
});
|
||||
test.skip('repeats the string a random amount of times', function () {
|
||||
xit('repeats the string a random amount of times', function () {
|
||||
/*The number is generated by using Math.random to get a value from between
|
||||
0 to 1, when this is multiplied by 1000 and rounded down with Math.floor it
|
||||
equals a number between 0 to 999 (this number will change everytime you run
|
||||
@@ -31,7 +31,7 @@ describe('repeatString', () => {
|
||||
was randomaly generated. */
|
||||
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
|
||||
});
|
||||
test.skip('works with blank strings', () => {
|
||||
xit('works with blank strings', function() {
|
||||
expect(repeatString('', 10)).toEqual('');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user