parent
888383a44e
commit
e353cd7f1f
|
@ -1,5 +1,5 @@
|
||||||
const helloWorld = function() {
|
const helloWorld = function() {
|
||||||
return ''
|
return 'Hello, World!'
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = helloWorld
|
module.exports = helloWorld
|
||||||
|
|
|
@ -1,5 +1,23 @@
|
||||||
const leapYears = function() {
|
const leapYears = function(year) {
|
||||||
|
let leapNonCenturyYear=year%4;
|
||||||
|
let leapCenturyYear=year%100;
|
||||||
|
let especiallyLeapYear=year%400;
|
||||||
|
let result;
|
||||||
|
if(leapNonCenturyYear == 0 && leapCenturyYear > 0)
|
||||||
|
{
|
||||||
|
result = true ;
|
||||||
|
}
|
||||||
|
else if(especiallyLeapYear == 0)
|
||||||
|
{
|
||||||
|
result =true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = leapYears
|
module.exports = leapYears
|
||||||
|
|
|
@ -4,19 +4,19 @@ describe('leapYears', function() {
|
||||||
it('works with non century years', function() {
|
it('works with non century years', function() {
|
||||||
expect(leapYears(1996)).toEqual(true);
|
expect(leapYears(1996)).toEqual(true);
|
||||||
});
|
});
|
||||||
xit('works with non century years', function() {
|
it('works with non century years', function() {
|
||||||
expect(leapYears(1997)).toEqual(false);
|
expect(leapYears(1997)).toEqual(false);
|
||||||
});
|
});
|
||||||
xit('works with ridiculously futuristic non century years', function() {
|
it('works with ridiculously futuristic non century years', function() {
|
||||||
expect(leapYears(34992)).toEqual(true);
|
expect(leapYears(34992)).toEqual(true);
|
||||||
});
|
});
|
||||||
xit('works with century years', function() {
|
it('works with century years', function() {
|
||||||
expect(leapYears(1900)).toEqual(false);
|
expect(leapYears(1900)).toEqual(false);
|
||||||
});
|
});
|
||||||
xit('works with century years', function() {
|
it('works with century years', function() {
|
||||||
expect(leapYears(1600)).toEqual(true);
|
expect(leapYears(1600)).toEqual(true);
|
||||||
});
|
});
|
||||||
xit('works with century years', function() {
|
it('works with century years', function() {
|
||||||
expect(leapYears(700)).toEqual(false);
|
expect(leapYears(700)).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const removeFromArray = function() {
|
const removeFromArray = function(arr,value,value2,value3,value4) {
|
||||||
|
return arr.filter(function(ele){ return ele !== value && ele !=value2 && ele !=value3 && ele !=value4; });
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = removeFromArray
|
module.exports = removeFromArray
|
||||||
|
|
|
@ -4,22 +4,22 @@ describe('removeFromArray', function() {
|
||||||
it('removes a single value', function() {
|
it('removes a single value', function() {
|
||||||
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
|
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
|
||||||
});
|
});
|
||||||
xit('removes multiple values', function() {
|
it('removes multiple values', function() {
|
||||||
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
|
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
|
||||||
});
|
});
|
||||||
xit('ignores non present values', function() {
|
it('ignores non present values', function() {
|
||||||
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
|
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
|
||||||
});
|
});
|
||||||
xit('ignores non present values, but still works', function() {
|
it('ignores non present values, but still works', function() {
|
||||||
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
|
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
|
||||||
});
|
});
|
||||||
xit('can remove all values', function() {
|
it('can remove all values', function() {
|
||||||
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
|
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
|
||||||
});
|
});
|
||||||
xit('works with strings', function() {
|
it('works with strings', function() {
|
||||||
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
|
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
|
||||||
});
|
});
|
||||||
xit('only removes same type', function() {
|
it('only removes same type', function() {
|
||||||
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
|
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
const repeatString = function() {
|
|
||||||
|
|
||||||
|
const repeatString = function(repeatText,times1) {
|
||||||
|
let fulltext =""
|
||||||
|
if(times1 >=0)
|
||||||
|
{for (var i = 0 ;i < times1; i++)
|
||||||
|
{
|
||||||
|
fulltext +=repeatText;
|
||||||
|
}
|
||||||
|
return fulltext;}
|
||||||
|
else return "ERROR";
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = repeatString
|
module.exports = repeatString
|
||||||
|
|
|
@ -4,19 +4,19 @@ describe('repeatString', function() {
|
||||||
it('repeats the string', function() {
|
it('repeats the string', function() {
|
||||||
expect(repeatString('hey', 3)).toEqual('heyheyhey');
|
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');
|
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');
|
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('');
|
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');
|
expect(repeatString('hey', -1)).toEqual('ERROR');
|
||||||
});
|
});
|
||||||
xit('repeats the string a random amount of times', function () {
|
it('repeats the string a random amount of times', function () {
|
||||||
/*The number is generated by using Math.random to get a value from between
|
/*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
|
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
|
equals a number between 0 to 999 (this number will change everytime you run
|
||||||
|
@ -27,7 +27,7 @@ describe('repeatString', function() {
|
||||||
was randomaly generated. */
|
was randomaly generated. */
|
||||||
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
|
expect(repeatString('hey', number).match(/((hey))/g).length).toEqual(number);
|
||||||
});
|
});
|
||||||
xit('works with blank strings', function() {
|
it('works with blank strings', function() {
|
||||||
expect(repeatString('', 10)).toEqual('');
|
expect(repeatString('', 10)).toEqual('');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
const reverseString = function() {
|
|
||||||
|
|
||||||
|
const reverseString = function(string1) {
|
||||||
|
let reverseText=""
|
||||||
|
for (var i = string1.length -1 ; i >= 0 ; i--)
|
||||||
|
{
|
||||||
|
reverseText +=string1[i];
|
||||||
|
|
||||||
|
}
|
||||||
|
return reverseText;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = reverseString
|
module.exports = reverseString
|
||||||
|
|
|
@ -5,14 +5,14 @@ describe('reverseString', function() {
|
||||||
expect(reverseString('hello')).toEqual('olleh');
|
expect(reverseString('hello')).toEqual('olleh');
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('reverses multiple words', function() {
|
it('reverses multiple words', function() {
|
||||||
expect(reverseString('hello there')).toEqual('ereht olleh')
|
expect(reverseString('hello there')).toEqual('ereht olleh')
|
||||||
})
|
})
|
||||||
|
|
||||||
xit('works with numbers and punctuation', function() {
|
it('works with numbers and punctuation', function() {
|
||||||
expect(reverseString('123! abc!')).toEqual('!cba !321')
|
expect(reverseString('123! abc!')).toEqual('!cba !321')
|
||||||
})
|
})
|
||||||
xit('works with blank strings', function() {
|
it('works with blank strings', function() {
|
||||||
expect(reverseString('')).toEqual('')
|
expect(reverseString('')).toEqual('')
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
const sumAll = function() {
|
const sumAll = function(x,y) {
|
||||||
|
let max=Math.max(x,y);
|
||||||
|
let min=Math.min(x,y);
|
||||||
|
let sum=0;
|
||||||
|
|
||||||
|
for (let i=min ; i<=max;i++)
|
||||||
|
{sum+=i;}
|
||||||
|
if(min >=0 && typeof(x) == "number" && typeof(y)=="number")
|
||||||
|
return sum;
|
||||||
|
else
|
||||||
|
return "ERROR";
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = sumAll
|
module.exports = sumAll
|
||||||
|
|
|
@ -4,19 +4,19 @@ describe('sumAll', function() {
|
||||||
it('sums numbers within the range', function() {
|
it('sums numbers within the range', function() {
|
||||||
expect(sumAll(1, 4)).toEqual(10);
|
expect(sumAll(1, 4)).toEqual(10);
|
||||||
});
|
});
|
||||||
xit('works with large numbers', function() {
|
it('works with large numbers', function() {
|
||||||
expect(sumAll(1, 4000)).toEqual(8002000);
|
expect(sumAll(1, 4000)).toEqual(8002000);
|
||||||
});
|
});
|
||||||
xit('works with larger number first', function() {
|
it('works with larger number first', function() {
|
||||||
expect(sumAll(123, 1)).toEqual(7626);
|
expect(sumAll(123, 1)).toEqual(7626);
|
||||||
});
|
});
|
||||||
xit('returns ERROR with negative numbers', function() {
|
it('returns ERROR with negative numbers', function() {
|
||||||
expect(sumAll(-10, 4)).toEqual('ERROR');
|
expect(sumAll(-10, 4)).toEqual('ERROR');
|
||||||
});
|
});
|
||||||
xit('returns ERROR with non-number parameters', function() {
|
it('returns ERROR with non-number parameters', function() {
|
||||||
expect(sumAll(10, "90")).toEqual('ERROR');
|
expect(sumAll(10, "90")).toEqual('ERROR');
|
||||||
});
|
});
|
||||||
xit('returns ERROR with non-number parameters', function() {
|
it('returns ERROR with non-number parameters', function() {
|
||||||
expect(sumAll(10, [90, 1])).toEqual('ERROR');
|
expect(sumAll(10, [90, 1])).toEqual('ERROR');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
const ftoc = function() {
|
const ftoc = function(temperature) {
|
||||||
|
return parseFloat(((temperature - 32)/1.8).toFixed(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
const ctof = function() {
|
const ctof = function(temperature) {
|
||||||
|
return parseFloat(((temperature*1.8)+32).toFixed(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -4,22 +4,22 @@ describe('ftoc', function() {
|
||||||
it('works', function() {
|
it('works', function() {
|
||||||
expect(ftoc(32)).toEqual(0);
|
expect(ftoc(32)).toEqual(0);
|
||||||
});
|
});
|
||||||
xit('rounds to 1 decimal', function() {
|
it('rounds to 1 decimal', function() {
|
||||||
expect(ftoc(100)).toEqual(37.8);
|
expect(ftoc(100)).toEqual(37.8);
|
||||||
});
|
});
|
||||||
xit('works with negatives', function() {
|
it('works with negatives', function() {
|
||||||
expect(ftoc(-100)).toEqual(-73.3);
|
expect(ftoc(-100)).toEqual(-73.3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ctof', function() {
|
describe('ctof', function() {
|
||||||
xit('works', function() {
|
it('works', function() {
|
||||||
expect(ctof(0)).toEqual(32);
|
expect(ctof(0)).toEqual(32);
|
||||||
});
|
});
|
||||||
xit('rounds to 1 decimal', function() {
|
it('rounds to 1 decimal', function() {
|
||||||
expect(ctof(73.2)).toEqual(163.8);
|
expect(ctof(73.2)).toEqual(163.8);
|
||||||
});
|
});
|
||||||
xit('works with negatives', function() {
|
it('works with negatives', function() {
|
||||||
expect(ctof(-10)).toEqual(14);
|
expect(ctof(-10)).toEqual(14);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue