From 933d74a287395cb361a7a54fc78036446564c4c8 Mon Sep 17 00:00:00 2001 From: "aidwiz@yahoo.com" Date: Tue, 3 Sep 2019 20:35:32 +0800 Subject: [PATCH] complete five tasks --- leapYears/leapYears.js | 15 +++++++++++- leapYears/leapYears.spec.js | 10 ++++---- leapYears/test.html | 13 ++++++++++ leapYears/test.js | 14 +++++++++++ removeFromArray/removeFromArray.js | 6 ++++- removeFromArray/test.html | 13 ++++++++++ removeFromArray/test.js | 35 +++++++++++++++++++++++++++ sumAll/sumAll.js | 21 ++++++++++++++-- sumAll/sumAll.spec.js | 10 ++++---- sumAll/test.html | 13 ++++++++++ sumAll/test.js | 23 ++++++++++++++++++ tempConversion/tempConversion.js | 13 +++++++--- tempConversion/tempConversion.spec.js | 10 ++++---- tempConversion/test.html | 13 ++++++++++ tempConversion/test.js | 32 ++++++++++++++++++++++++ 15 files changed, 218 insertions(+), 23 deletions(-) create mode 100644 leapYears/test.html create mode 100644 leapYears/test.js create mode 100644 removeFromArray/test.html create mode 100644 removeFromArray/test.js create mode 100644 sumAll/test.html create mode 100644 sumAll/test.js create mode 100644 tempConversion/test.html create mode 100644 tempConversion/test.js diff --git a/leapYears/leapYears.js b/leapYears/leapYears.js index ac786a2..a3eaeda 100644 --- a/leapYears/leapYears.js +++ b/leapYears/leapYears.js @@ -1,4 +1,17 @@ -const leapYears = function() { +const leapYears = function(year) { + + if (year % 4 === 0 && year % 100 > 0) { + // console.log("leap"); + return true; + } else { + if (year % 400 === 0) { + // console.log("leap 2"); + return true; + } else { + // console.log("not leap"); + return false; + } + } } diff --git a/leapYears/leapYears.spec.js b/leapYears/leapYears.spec.js index 0d4d7d4..f4cdea8 100644 --- a/leapYears/leapYears.spec.js +++ b/leapYears/leapYears.spec.js @@ -4,19 +4,19 @@ describe('leapYears', function() { it('works with non century years', function() { expect(leapYears(1996)).toEqual(true); }); - xit('works with non century years', function() { + it('works with non century years', function() { 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); }); - xit('works with century years', function() { + it('works with century years', function() { expect(leapYears(1900)).toEqual(false); }); - xit('works with century years', function() { + it('works with century years', function() { expect(leapYears(1600)).toEqual(true); }); - xit('works with century years', function() { + it('works with century years', function() { expect(leapYears(700)).toEqual(false); }); }); diff --git a/leapYears/test.html b/leapYears/test.html new file mode 100644 index 0000000..0e165d3 --- /dev/null +++ b/leapYears/test.html @@ -0,0 +1,13 @@ + + + + + + + Document + + + + + + \ No newline at end of file diff --git a/leapYears/test.js b/leapYears/test.js new file mode 100644 index 0000000..56d6bb2 --- /dev/null +++ b/leapYears/test.js @@ -0,0 +1,14 @@ +function leapYears(year) { + + if (year % 4 === 0 && year % 100 > 0) { + console.log("leap"); + } else { + if (year % 400 === 0) { + console.log("leap 2"); + } else { + console.log("not leap"); + } + } + +} +leapYears(700); \ No newline at end of file diff --git a/removeFromArray/removeFromArray.js b/removeFromArray/removeFromArray.js index 11efd5c..f849f79 100644 --- a/removeFromArray/removeFromArray.js +++ b/removeFromArray/removeFromArray.js @@ -1,5 +1,9 @@ -const removeFromArray = function() { +const removeFromArray = function(arg) { + console.log(arguments[0]); + + for (let i=0; i + + + + + + Document + + + + + + \ No newline at end of file diff --git a/removeFromArray/test.js b/removeFromArray/test.js new file mode 100644 index 0000000..0d5575c --- /dev/null +++ b/removeFromArray/test.js @@ -0,0 +1,35 @@ +function removeFromArray(parameters) { + // success with single arguments + // let array1 = array; + // let array2 = []; + + // for (i=0; i + + + + + + Document + + + + + + \ No newline at end of file diff --git a/sumAll/test.js b/sumAll/test.js new file mode 100644 index 0000000..5d73764 --- /dev/null +++ b/sumAll/test.js @@ -0,0 +1,23 @@ +function sumAll(first, second) { + + if(first < 0 || typeof(second) === 'string' || Array.isArray(second) ) { + return "ERROR"; + } else { + let sum = 0; + if (first < second) { + for (let i = first; i <= second; i++) { + sum = sum + i; + // console.log(sum); + } + } else { + for (let i = second; i <= first; i++) { + sum = sum + i; + // console.log(sum); + } + } + return sum; + } + +} +// let result = sumAll(1,4); +console.log(sumAll(10,[90,1])); diff --git a/tempConversion/tempConversion.js b/tempConversion/tempConversion.js index 4fa21ee..4b030f9 100644 --- a/tempConversion/tempConversion.js +++ b/tempConversion/tempConversion.js @@ -1,12 +1,17 @@ -const ftoc = function() { - +const ftoc = function(fahrenheit) { + let celcius = ((fahrenheit - 32) * 5) / 9; + let rounded1 = Math.round(celcius * 10) / 10; + return rounded1; } -const ctof = function() { - +const ctof = function(celcius) { + let fahrenheit = (celcius * 9) / 5 + 32; + let rounded2 = Math.round(fahrenheit * 10) / 10; + return rounded2; } module.exports = { ftoc, ctof } + 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); }); }); diff --git a/tempConversion/test.html b/tempConversion/test.html new file mode 100644 index 0000000..0e165d3 --- /dev/null +++ b/tempConversion/test.html @@ -0,0 +1,13 @@ + + + + + + + Document + + + + + + \ No newline at end of file diff --git a/tempConversion/test.js b/tempConversion/test.js new file mode 100644 index 0000000..f6dcafb --- /dev/null +++ b/tempConversion/test.js @@ -0,0 +1,32 @@ +function ftoc(fahrenheit) { + + // let celcius = ((fahrenheit-32)*5/9).toFixed(1); + // let fixed = celcius.toFixed(1); + //tofixed converts number to string - problem, UI is OK + // let celcius = (((fahrenheit - 32) * 5) / 9).toFixed(1); + // let fixed = parseInt(celcius).toFixed(1); + + let celcius = ((fahrenheit - 32) * 5) / 9; + let rounded1 = Math.round(celcius * 10) / 10; + + console.log(typeof rounded1); + console.log(rounded1); + +} + +function ctof(celcius) { + + let fahrenheit = ((celcius * 9 / 5) + 32); + let rounded2 = Math.round(fahrenheit * 10) / 10; + + console.log(typeof rounded2); + console.log(rounded2); + +} + +ftoc(32); +ftoc(100); +ftoc(-100); +ctof(0); +ctof(73.2); +ctof(-10); \ No newline at end of file