Compare commits

...

10 Commits

Author SHA1 Message Date
NetMan 4cb2fa66b9 Passes all tests from toFahrenheit in exercise 07
in conclusion passes all tests!
2024-01-05 22:08:37 +01:00
NetMan 08d14383b0 Passed tests 2 & 3 toCelsius from exercise 07
added Math.round

essentially multiplying inside of round, and dividing out of it will increase the rounding decimal point
2024-01-05 22:06:28 +01:00
NetMan 46732dbe89 Passed test 1 toCelsius from exercise 07 2024-01-05 22:03:43 +01:00
NetMan 4938e86830 Passed all tests from exercise 06
lightning fast ;)
2024-01-05 22:00:05 +01:00
NetMan c47a205e6f Passed final tests for exercise 05 2024-01-05 21:56:46 +01:00
NetMan 77972b4282 Passes test 4 from exercise 05 2024-01-05 21:46:07 +01:00
NetMan 56cdd5935c Passes test 3 from exercise 05 2024-01-05 21:43:56 +01:00
NetMan 43e2839177 Passes test 1 and 2 from exercise 05 2024-01-05 21:37:06 +01:00
NetMan a308d40fee Passed final test from exercise 04 2024-01-05 21:34:14 +01:00
NetMan 1d72ec8b14 Passed fifth and sixth test from exercise 04 2024-01-05 21:33:43 +01:00
8 changed files with 46 additions and 28 deletions

View File

@ -1,9 +1,9 @@
const removeFromArray = function(array, ...remove) {
remove.forEach(element => {
let findIndexElement = array.findIndex(x => x == element);
let findIndexElement = array.findIndex(x => x === element);
if (findIndexElement >= 0) {
let saveArray = [];
for (let i = 0; i < array.length - findIndexElement; i++) {
for (let i = 0, arrayLength = array.length; i < arrayLength - findIndexElement - 1; i++) {
saveArray.push(array.pop());
}
array.pop();
@ -15,7 +15,5 @@ const removeFromArray = function(array, ...remove) {
return array;
};
removeFromArray([1, 2, 3, 4], 7, 2);
// Do not edit below this line
module.exports = removeFromArray;

View File

@ -13,13 +13,13 @@ describe('removeFromArray', () => {
test('ignores non present values, but still works', () => {
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
});
test.skip('can remove all values', () => {
test('can remove all values', () => {
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
});
test.skip('works with strings', () => {
test('works with strings', () => {
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
});
test.skip('only removes same type', () => {
test('only removes same type', () => {
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
});
});

View File

@ -1,5 +1,13 @@
const sumAll = function() {
const sumAll = function(a, b) {
if (a < 0 || b < 0 || typeof(a) != "number"|| typeof(b) != "number") {
return "ERROR";
}
let c, sum = 0;
for ((a > b) ? (i = b, c = a)
: (i = a, c = b); i <= c; i++) {
sum += i;
}
return sum;
};
// Do not edit below this line

View File

@ -4,19 +4,19 @@ describe('sumAll', () => {
test('sums numbers within the range', () => {
expect(sumAll(1, 4)).toEqual(10);
});
test.skip('works with large numbers', () => {
test('works with large numbers', () => {
expect(sumAll(1, 4000)).toEqual(8002000);
});
test.skip('works with larger number first', () => {
test('works with larger number first', () => {
expect(sumAll(123, 1)).toEqual(7626);
});
test.skip('returns ERROR with negative numbers', () => {
test('returns ERROR with negative numbers', () => {
expect(sumAll(-10, 4)).toEqual('ERROR');
});
test.skip('returns ERROR with non-number parameters', () => {
test('returns ERROR with non-number parameters', () => {
expect(sumAll(10, "90")).toEqual('ERROR');
});
test.skip('returns ERROR with non-number parameters', () => {
test('returns ERROR with non-number parameters', () => {
expect(sumAll(10, [90, 1])).toEqual('ERROR');
});
});

View File

@ -1,5 +1,14 @@
const leapYears = function() {
const leapYears = function(year) {
if (year % 400 == 0) {
return true;
}
if (year % 100 == 0) {
return false;
}
if (year % 4 == 0) {
return true;
}
return false;
};
// Do not edit below this line

View File

@ -4,19 +4,19 @@ describe('leapYears', () => {
test('works with non century years', () => {
expect(leapYears(1996)).toBe(true);
});
test.skip('works with non century years', () => {
test('works with non century years', () => {
expect(leapYears(1997)).toBe(false);
});
test.skip('works with ridiculously futuristic non century years', () => {
test('works with ridiculously futuristic non century years', () => {
expect(leapYears(34992)).toBe(true);
});
test.skip('works with century years', () => {
test('works with century years', () => {
expect(leapYears(1900)).toBe(false);
});
test.skip('works with century years', () => {
test('works with century years', () => {
expect(leapYears(1600)).toBe(true);
});
test.skip('works with century years', () => {
test('works with century years', () => {
expect(leapYears(700)).toBe(false);
});
});

View File

@ -1,7 +1,10 @@
const convertToCelsius = function() {
const convertToCelsius = function(deg) {
return Math.round((deg - 32) * (5/9) * 10) / 10;
};
const convertToFahrenheit = function() {
const convertToFahrenheit = function(deg) {
return Math.round((deg * (9/5) + 32) * 10) / 10;
// x °C ≘ (x ×9/5+ 32) °F
};
// Do not edit below this line

View File

@ -4,22 +4,22 @@ describe('convertToCelsius', () => {
test('works', () => {
expect(convertToCelsius(32)).toEqual(0);
});
test.skip('rounds to 1 decimal', () => {
test('rounds to 1 decimal', () => {
expect(convertToCelsius(100)).toEqual(37.8);
});
test.skip('works with negatives', () => {
test('works with negatives', () => {
expect(convertToCelsius(-100)).toEqual(-73.3);
});
});
describe('convertToFahrenheit', () => {
test.skip('works', () => {
test('works', () => {
expect(convertToFahrenheit(0)).toEqual(32);
});
test.skip('rounds to 1 decimal', () => {
test('rounds to 1 decimal', () => {
expect(convertToFahrenheit(73.2)).toEqual(163.8);
});
test.skip('works with negatives', () => {
test('works with negatives', () => {
expect(convertToFahrenheit(-10)).toEqual(14);
});
});