Koncan do 7 vaje
This commit is contained in:
parent
c43f64e3e8
commit
4741f6b23c
|
@ -1,4 +1,18 @@
|
|||
const sumAll = function() {
|
||||
const sumAll = function(from, to) {
|
||||
let sum = 0;
|
||||
if(from > to){
|
||||
[from, to] = [to, from];
|
||||
}
|
||||
if(from < 0 || to < 0){
|
||||
return "ERROR";
|
||||
}
|
||||
if(!Number.isInteger(from) || !Number.isInteger(to)){
|
||||
return "ERROR";
|
||||
}
|
||||
for(from; from <= to; from++){
|
||||
sum += from;
|
||||
}
|
||||
return sum;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -4,19 +4,19 @@ describe('sumAll', () => {
|
|||
test('sums numbers within the range', () => {
|
||||
expect(sumAll(1, 4)).toEqual(10);
|
||||
});
|
||||
test.skip('works with large numbers', () => {
|
||||
test('works with large numbers', () => {
|
||||
expect(sumAll(1, 4000)).toEqual(8002000);
|
||||
});
|
||||
test.skip('works with larger number first', () => {
|
||||
test('works with larger number first', () => {
|
||||
expect(sumAll(123, 1)).toEqual(7626);
|
||||
});
|
||||
test.skip('returns ERROR with negative numbers', () => {
|
||||
test('returns ERROR with negative numbers', () => {
|
||||
expect(sumAll(-10, 4)).toEqual('ERROR');
|
||||
});
|
||||
test.skip('returns ERROR with non-number parameters', () => {
|
||||
test('returns ERROR with non-number parameters', () => {
|
||||
expect(sumAll(10, "90")).toEqual('ERROR');
|
||||
});
|
||||
test.skip('returns ERROR with non-number parameters', () => {
|
||||
test('returns ERROR with non-number parameters', () => {
|
||||
expect(sumAll(10, [90, 1])).toEqual('ERROR');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
const leapYears = function() {
|
||||
|
||||
const leapYears = function(year) {
|
||||
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
|
||||
};
|
||||
|
||||
// Leap years are years divisible by four (like 1984 and 2004). However,
|
||||
//years divisible by 100 are not leap years (such as 1800 and 1900) unless they are divisible by 400 (like 1600 and 2000, which were in fact leap years). (Yes, it's all pretty confusing)
|
||||
|
||||
// Do not edit below this line
|
||||
module.exports = leapYears;
|
||||
|
|
|
@ -4,19 +4,19 @@ describe('leapYears', () => {
|
|||
test('works with non century years', () => {
|
||||
expect(leapYears(1996)).toBe(true);
|
||||
});
|
||||
test.skip('works with non century years', () => {
|
||||
test('works with non century years', () => {
|
||||
expect(leapYears(1997)).toBe(false);
|
||||
});
|
||||
test.skip('works with ridiculously futuristic non century years', () => {
|
||||
test('works with ridiculously futuristic non century years', () => {
|
||||
expect(leapYears(34992)).toBe(true);
|
||||
});
|
||||
test.skip('works with century years', () => {
|
||||
test('works with century years', () => {
|
||||
expect(leapYears(1900)).toBe(false);
|
||||
});
|
||||
test.skip('works with century years', () => {
|
||||
test('works with century years', () => {
|
||||
expect(leapYears(1600)).toBe(true);
|
||||
});
|
||||
test.skip('works with century years', () => {
|
||||
test('works with century years', () => {
|
||||
expect(leapYears(700)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
const convertToCelsius = function() {
|
||||
const convertToCelsius = function (fahrenheit) {
|
||||
return Math.round((fahrenheit - 32) * (5 / 9) * 10) / 10;
|
||||
};
|
||||
|
||||
const convertToFahrenheit = function() {
|
||||
const convertToFahrenheit = function (celsius) {
|
||||
return Math.round(((celsius * 9) / 5 + 32) * 10) / 10;
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
|
|
|
@ -4,22 +4,22 @@ describe('convertToCelsius', () => {
|
|||
test('works', () => {
|
||||
expect(convertToCelsius(32)).toEqual(0);
|
||||
});
|
||||
test.skip('rounds to 1 decimal', () => {
|
||||
test('rounds to 1 decimal', () => {
|
||||
expect(convertToCelsius(100)).toEqual(37.8);
|
||||
});
|
||||
test.skip('works with negatives', () => {
|
||||
test('works with negatives', () => {
|
||||
expect(convertToCelsius(-100)).toEqual(-73.3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertToFahrenheit', () => {
|
||||
test.skip('works', () => {
|
||||
test('works', () => {
|
||||
expect(convertToFahrenheit(0)).toEqual(32);
|
||||
});
|
||||
test.skip('rounds to 1 decimal', () => {
|
||||
test('rounds to 1 decimal', () => {
|
||||
expect(convertToFahrenheit(73.2)).toEqual(163.8);
|
||||
});
|
||||
test.skip('works with negatives', () => {
|
||||
test('works with negatives', () => {
|
||||
expect(convertToFahrenheit(-10)).toEqual(14);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue