diff --git a/05_sumAll/sumAll.js b/05_sumAll/sumAll.js index 00880c7..b13e4e5 100644 --- a/05_sumAll/sumAll.js +++ b/05_sumAll/sumAll.js @@ -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; }; diff --git a/05_sumAll/sumAll.spec.js b/05_sumAll/sumAll.spec.js index 1a9fb7c..a171e5f 100644 --- a/05_sumAll/sumAll.spec.js +++ b/05_sumAll/sumAll.spec.js @@ -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'); }); }); diff --git a/06_leapYears/leapYears.js b/06_leapYears/leapYears.js index 681eeef..3e34736 100644 --- a/06_leapYears/leapYears.js +++ b/06_leapYears/leapYears.js @@ -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; diff --git a/06_leapYears/leapYears.spec.js b/06_leapYears/leapYears.spec.js index 6fdaba9..2cd4110 100644 --- a/06_leapYears/leapYears.spec.js +++ b/06_leapYears/leapYears.spec.js @@ -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); }); }); diff --git a/07_tempConversion/tempConversion.js b/07_tempConversion/tempConversion.js index 14153e0..d9926e9 100644 --- a/07_tempConversion/tempConversion.js +++ b/07_tempConversion/tempConversion.js @@ -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 diff --git a/07_tempConversion/tempConversion.spec.js b/07_tempConversion/tempConversion.spec.js index c4f9742..7d0cc93 100644 --- a/07_tempConversion/tempConversion.spec.js +++ b/07_tempConversion/tempConversion.spec.js @@ -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); }); });