my TDD exercises solutions
This commit is contained in:
parent
888383a44e
commit
7f6b7dc5b1
|
@ -1,5 +1,5 @@
|
|||
const leapYears = function() {
|
||||
const leapYears = function (year) {
|
||||
return year % 4 == 0 && (year % 100 !== 0 || year % 400 == 0);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
module.exports = leapYears
|
||||
module.exports = leapYears;
|
||||
|
|
|
@ -1,5 +1,19 @@
|
|||
const removeFromArray = function() {
|
||||
const removeFromArray = function (...theArgs) {
|
||||
let filteredArr = [],
|
||||
arr = theArgs[0];
|
||||
|
||||
}
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
// theArgs.map((arg) => {
|
||||
// if (arr[i] != arg) {
|
||||
// filteredArr.push(arr[i]);
|
||||
// }
|
||||
// });
|
||||
if (!theArgs.includes(arr[i])) {
|
||||
filteredArr.push(arr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = removeFromArray
|
||||
return filteredArr;
|
||||
};
|
||||
|
||||
module.exports = removeFromArray;
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
const repeatString = function() {
|
||||
const repeatString = function (s, n) {
|
||||
let newString = "";
|
||||
if (n < 0) {
|
||||
newString = "ERROR";
|
||||
}
|
||||
|
||||
}
|
||||
for (let i = 0; i < n; i++) {
|
||||
newString = newString + s;
|
||||
}
|
||||
return newString;
|
||||
};
|
||||
|
||||
module.exports = repeatString
|
||||
module.exports = repeatString;
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
const reverseString = function() {
|
||||
const reverseString = function (s) {
|
||||
s = s.split("");
|
||||
let newWord = [];
|
||||
for (let i = s.length - 1; i >= 0; i--) {
|
||||
newWord.push(s[i]);
|
||||
}
|
||||
return newWord.join("");
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
module.exports = reverseString
|
||||
module.exports = reverseString;
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
const sumAll = function() {
|
||||
const sumAll = function (a, b) {
|
||||
let max = a > b ? a : b,
|
||||
min = a < b ? a : b;
|
||||
|
||||
}
|
||||
let sum = 0;
|
||||
for (let i = min; i <= max; i++) {
|
||||
sum += i;
|
||||
}
|
||||
return a < 0 || b < 0 || typeof a !== "number" || typeof b !== "number"
|
||||
? "ERROR"
|
||||
: sum;
|
||||
};
|
||||
|
||||
module.exports = sumAll
|
||||
module.exports = sumAll;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
const ftoc = function() {
|
||||
const ftoc = function (temp) {
|
||||
return Math.round((((temp - 32) * 5) / 9) * 10) / 10;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
const ctof = function() {
|
||||
|
||||
}
|
||||
const ctof = function (temp) {
|
||||
return Math.round(((temp * 9) / 5 + 32) * 10) / 10;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
ftoc,
|
||||
ctof
|
||||
}
|
||||
ctof,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue