From 3bbe72b2c021f7b33776afd210cd058daa19d5f9 Mon Sep 17 00:00:00 2001 From: Kira Date: Mon, 27 Aug 2018 18:35:29 +0000 Subject: [PATCH] Wrote solution to tempConversion exercise --- leapYears/leapYears.js | 12 ++---------- tempConversion/tempConversion.js | 10 ++++++---- tempConversion/tempConversion.spec.js | 10 +++++----- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/leapYears/leapYears.js b/leapYears/leapYears.js index 5b16de1..db92e2d 100644 --- a/leapYears/leapYears.js +++ b/leapYears/leapYears.js @@ -1,13 +1,5 @@ -const leapYears = function(date) { - if (date % 4 === 0) { - if (date % 100 === 0 && date % 400 !== 0) { - return false; - } else { - return true; - } - } else { - return false; - } +const leapYears = function(year) { + return year % 4 === 0 && (year % 100 !== 0 || year % 400 == 0) } module.exports = leapYears diff --git a/tempConversion/tempConversion.js b/tempConversion/tempConversion.js index 4fa21ee..7c2ab3a 100644 --- a/tempConversion/tempConversion.js +++ b/tempConversion/tempConversion.js @@ -1,9 +1,11 @@ -const ftoc = function() { - +const ftoc = function(tempInF) { + let tempInC = (tempInF - 32) * 5/9; + return Math.round(tempInC * 10) / 10; } -const ctof = function() { - +const ctof = function(tempInC) { + let tempInF = tempInC * 9/5 + 32; + return Math.round(tempInF * 10) / 10; } module.exports = { diff --git a/tempConversion/tempConversion.spec.js b/tempConversion/tempConversion.spec.js index 0dc9168..bdb7c0e 100644 --- a/tempConversion/tempConversion.spec.js +++ b/tempConversion/tempConversion.spec.js @@ -4,22 +4,22 @@ describe('ftoc', function() { it('works', function() { expect(ftoc(32)).toEqual(0); }); - xit('rounds to 1 decimal', function() { + it('rounds to 1 decimal', function() { expect(ftoc(100)).toEqual(37.8); }); - xit('works with negatives', function() { + it('works with negatives', function() { expect(ftoc(-100)).toEqual(-73.3); }); }); describe('ctof', function() { - xit('works', function() { + it('works', function() { expect(ctof(0)).toEqual(32); }); - xit('rounds to 1 decimal', function() { + it('rounds to 1 decimal', function() { expect(ctof(73.2)).toEqual(163.8); }); - xit('works with negatives', function() { + it('works with negatives', function() { expect(ctof(-10)).toEqual(14); }); });