complete five tasks
This commit is contained in:
		
							parent
							
								
									cc479b5e70
								
							
						
					
					
						commit
						933d74a287
					
				| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,22 @@
 | 
			
		|||
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;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = sumAll
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,19 +4,19 @@ describe('sumAll', function() {
 | 
			
		|||
  it('sums numbers within the range', function() {
 | 
			
		||||
    expect(sumAll(1, 4)).toEqual(10);
 | 
			
		||||
  });
 | 
			
		||||
  xit('works with large numbers', function() {
 | 
			
		||||
  it('works with large numbers', function() {
 | 
			
		||||
    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);
 | 
			
		||||
  });
 | 
			
		||||
  xit('returns ERROR with negative numbers', function() {
 | 
			
		||||
  it('returns ERROR with negative numbers', function() {
 | 
			
		||||
    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');
 | 
			
		||||
  });
 | 
			
		||||
  xit('returns ERROR with non-number parameters', function() {
 | 
			
		||||
  it('returns ERROR with non-number parameters', function() {
 | 
			
		||||
    expect(sumAll(10, [90, 1])).toEqual('ERROR');
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			@ -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]));
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
		Loading…
	
		Reference in New Issue