complete five tasks

This commit is contained in:
aidwiz@yahoo.com 2019-09-03 20:35:32 +08:00
parent cc479b5e70
commit 933d74a287
15 changed files with 218 additions and 23 deletions

View File

@ -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;
}
}
} }

View File

@ -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);
}); });
}); });

13
leapYears/test.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="test.js"></script>
</body>
</html>

14
leapYears/test.js Normal file
View File

@ -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);

View File

@ -1,5 +1,9 @@
const removeFromArray = function() { const removeFromArray = function(arg) {
console.log(arguments[0]);
for (let i=0; i<receivedArray.length; i++) {
}
} }
module.exports = removeFromArray module.exports = removeFromArray

13
removeFromArray/test.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="test.js"></script>
</body>
</html>

35
removeFromArray/test.js Normal file
View File

@ -0,0 +1,35 @@
function removeFromArray(parameters) {
// success with single arguments
// let array1 = array;
// let array2 = [];
// for (i=0; i<array1.length; i++) {
// if (array1[i] == optionalParam) {
// array1.splice(i, 1);
// i--;
// }
// }
// console.log(array1);
// }
//multiple arguments
var outerArray = Array.from(arguments);
console.log(arguments);
var insideArray = outerArray[0];
console.log(insideArray);
for (i=1; i<outerArray.length; i++) {
// console.log('loop' + i);
console.log('outerArray :' + outerArray[i]);
for(j=0; j<insideArray.length; j++) {
// console.log('insideArray :' + insideArray[j]);
if (insideArray[j] === outerArray[i]) {
insideArray.splice(j,1);
j--;
}
}
}
console.log(insideArray);
}
removeFromArray([10,2,5,6,2,8,4], 10);

View File

@ -1,4 +1,21 @@
const sumAll = function() { const sumAll = function(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;
}
} }

View File

@ -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');
}); });
}); });

13
sumAll/test.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="test.js"></script>
</body>
</html>

23
sumAll/test.js Normal file
View File

@ -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]));

View File

@ -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 = { module.exports = {
ftoc, ftoc,
ctof ctof
} }

View File

@ -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);
}); });
}); });

13
tempConversion/test.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="test.js"></script>
</body>
</html>

32
tempConversion/test.js Normal file
View File

@ -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);