Complete the helloWorld,repeatString and reverseString exercices with jasmine tests
This commit is contained in:
parent
b2e42072de
commit
ee8204f99d
|
@ -1,5 +1,5 @@
|
|||
const helloWorld = function() {
|
||||
return ''
|
||||
return 'Hello, World!'
|
||||
}
|
||||
|
||||
module.exports = helloWorld
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
const repeatString = function() {
|
||||
|
||||
}
|
||||
const repeatString = function(repeat,j) {
|
||||
if (j<0){
|
||||
return 'ERROR';
|
||||
}else{
|
||||
var str = '';
|
||||
for (var i=0; i<j; i++){
|
||||
str=str+repeat;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = repeatString
|
||||
|
|
|
@ -4,16 +4,16 @@ describe('repeatString', function() {
|
|||
it('repeats the string', function() {
|
||||
expect(repeatString('hey', 3)).toEqual('heyheyhey');
|
||||
});
|
||||
xit('repeats the string many times', function() {
|
||||
it('repeats the string many times', function() {
|
||||
expect(repeatString('hey', 10)).toEqual('heyheyheyheyheyheyheyheyheyhey');
|
||||
});
|
||||
xit('repeats the string 1 times', function() {
|
||||
it('repeats the string 1 times', function() {
|
||||
expect(repeatString('hey', 1)).toEqual('hey');
|
||||
});
|
||||
xit('repeats the string 0 times', function() {
|
||||
it('repeats the string 0 times', function() {
|
||||
expect(repeatString('hey', 0)).toEqual('');
|
||||
});
|
||||
xit('returns ERROR with negative numbers', function() {
|
||||
it('returns ERROR with negative numbers', function() {
|
||||
expect(repeatString('hey', -1)).toEqual('ERROR');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
const reverseString = function() {
|
||||
const reverseString = function(str) {
|
||||
let splitString = str.split("");
|
||||
|
||||
let reverseArray = splitString.reverse();
|
||||
|
||||
let joinArray = reverseArray.join("");
|
||||
|
||||
return joinArray;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = reverseString
|
||||
|
|
|
@ -5,7 +5,7 @@ describe('reverseString', function() {
|
|||
expect(reverseString('hello')).toEqual('olleh');
|
||||
});
|
||||
|
||||
xit('reverses multiple words', function() {
|
||||
it('reverses multiple words', function() {
|
||||
expect(reverseString('hello there')).toEqual('ereht olleh')
|
||||
})
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"spec_dir": "spec",
|
||||
"spec_files": [
|
||||
"**/*[sS]pec.js"
|
||||
],
|
||||
"helpers": [
|
||||
"helpers/**/*.js"
|
||||
],
|
||||
"stopSpecOnExpectationFailure": false,
|
||||
"random": true
|
||||
}
|
Loading…
Reference in New Issue