Compare commits
10 Commits
f0c8df6081
...
4cb2fa66b9
Author | SHA1 | Date |
---|---|---|
NetMan | 4cb2fa66b9 | |
NetMan | 08d14383b0 | |
NetMan | 46732dbe89 | |
NetMan | 4938e86830 | |
NetMan | c47a205e6f | |
NetMan | 77972b4282 | |
NetMan | 56cdd5935c | |
NetMan | 43e2839177 | |
NetMan | a308d40fee | |
NetMan | 1d72ec8b14 |
|
@ -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;
|
||||
|
|
|
@ -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]);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue