my TDD exercises solutions

This commit is contained in:
vfonsah 2020-08-28 23:50:20 +01:00
parent 888383a44e
commit 7f6b7dc5b1
6 changed files with 61 additions and 25 deletions

View File

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

View File

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

View File

@ -1,5 +1,13 @@
const repeatString = function() { const repeatString = function (s, n) {
let newString = "";
if (n < 0) {
newString = "ERROR";
} }
module.exports = repeatString for (let i = 0; i < n; i++) {
newString = newString + s;
}
return newString;
};
module.exports = repeatString;

View File

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

View File

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

View File

@ -1,12 +1,12 @@
const ftoc = function() { const ftoc = function (temp) {
return Math.round((((temp - 32) * 5) / 9) * 10) / 10;
};
} const ctof = function (temp) {
return Math.round(((temp * 9) / 5 + 32) * 10) / 10;
const ctof = function() { };
}
module.exports = { module.exports = {
ftoc, ftoc,
ctof ctof,
} };