Compare commits
No commits in common. "4cb2fa66b9d773b656f5827c4fdd85dc99006a20" and "f0c8df60817495c72c7a0aac497cc6f0025dbfc0" have entirely different histories.
4cb2fa66b9
...
f0c8df6081
|
@ -1,9 +1,9 @@
|
||||||
const removeFromArray = function(array, ...remove) {
|
const removeFromArray = function(array, ...remove) {
|
||||||
remove.forEach(element => {
|
remove.forEach(element => {
|
||||||
let findIndexElement = array.findIndex(x => x === element);
|
let findIndexElement = array.findIndex(x => x == element);
|
||||||
if (findIndexElement >= 0) {
|
if (findIndexElement >= 0) {
|
||||||
let saveArray = [];
|
let saveArray = [];
|
||||||
for (let i = 0, arrayLength = array.length; i < arrayLength - findIndexElement - 1; i++) {
|
for (let i = 0; i < array.length - findIndexElement; i++) {
|
||||||
saveArray.push(array.pop());
|
saveArray.push(array.pop());
|
||||||
}
|
}
|
||||||
array.pop();
|
array.pop();
|
||||||
|
@ -15,5 +15,7 @@ const removeFromArray = function(array, ...remove) {
|
||||||
return array;
|
return array;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
removeFromArray([1, 2, 3, 4], 7, 2);
|
||||||
|
|
||||||
// Do not edit below this line
|
// Do not edit below this line
|
||||||
module.exports = removeFromArray;
|
module.exports = removeFromArray;
|
||||||
|
|
|
@ -13,13 +13,13 @@ describe('removeFromArray', () => {
|
||||||
test('ignores non present values, but still works', () => {
|
test('ignores non present values, but still works', () => {
|
||||||
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
|
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]);
|
||||||
});
|
});
|
||||||
test('can remove all values', () => {
|
test.skip('can remove all values', () => {
|
||||||
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
|
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]);
|
||||||
});
|
});
|
||||||
test('works with strings', () => {
|
test.skip('works with strings', () => {
|
||||||
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
|
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]);
|
||||||
});
|
});
|
||||||
test('only removes same type', () => {
|
test.skip('only removes same type', () => {
|
||||||
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
|
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
const sumAll = function(a, b) {
|
const sumAll = function() {
|
||||||
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
|
// Do not edit below this line
|
||||||
|
|
|
@ -4,19 +4,19 @@ describe('sumAll', () => {
|
||||||
test('sums numbers within the range', () => {
|
test('sums numbers within the range', () => {
|
||||||
expect(sumAll(1, 4)).toEqual(10);
|
expect(sumAll(1, 4)).toEqual(10);
|
||||||
});
|
});
|
||||||
test('works with large numbers', () => {
|
test.skip('works with large numbers', () => {
|
||||||
expect(sumAll(1, 4000)).toEqual(8002000);
|
expect(sumAll(1, 4000)).toEqual(8002000);
|
||||||
});
|
});
|
||||||
test('works with larger number first', () => {
|
test.skip('works with larger number first', () => {
|
||||||
expect(sumAll(123, 1)).toEqual(7626);
|
expect(sumAll(123, 1)).toEqual(7626);
|
||||||
});
|
});
|
||||||
test('returns ERROR with negative numbers', () => {
|
test.skip('returns ERROR with negative numbers', () => {
|
||||||
expect(sumAll(-10, 4)).toEqual('ERROR');
|
expect(sumAll(-10, 4)).toEqual('ERROR');
|
||||||
});
|
});
|
||||||
test('returns ERROR with non-number parameters', () => {
|
test.skip('returns ERROR with non-number parameters', () => {
|
||||||
expect(sumAll(10, "90")).toEqual('ERROR');
|
expect(sumAll(10, "90")).toEqual('ERROR');
|
||||||
});
|
});
|
||||||
test('returns ERROR with non-number parameters', () => {
|
test.skip('returns ERROR with non-number parameters', () => {
|
||||||
expect(sumAll(10, [90, 1])).toEqual('ERROR');
|
expect(sumAll(10, [90, 1])).toEqual('ERROR');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,14 +1,5 @@
|
||||||
const leapYears = function(year) {
|
const leapYears = function() {
|
||||||
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
|
// Do not edit below this line
|
||||||
|
|
|
@ -4,19 +4,19 @@ describe('leapYears', () => {
|
||||||
test('works with non century years', () => {
|
test('works with non century years', () => {
|
||||||
expect(leapYears(1996)).toBe(true);
|
expect(leapYears(1996)).toBe(true);
|
||||||
});
|
});
|
||||||
test('works with non century years', () => {
|
test.skip('works with non century years', () => {
|
||||||
expect(leapYears(1997)).toBe(false);
|
expect(leapYears(1997)).toBe(false);
|
||||||
});
|
});
|
||||||
test('works with ridiculously futuristic non century years', () => {
|
test.skip('works with ridiculously futuristic non century years', () => {
|
||||||
expect(leapYears(34992)).toBe(true);
|
expect(leapYears(34992)).toBe(true);
|
||||||
});
|
});
|
||||||
test('works with century years', () => {
|
test.skip('works with century years', () => {
|
||||||
expect(leapYears(1900)).toBe(false);
|
expect(leapYears(1900)).toBe(false);
|
||||||
});
|
});
|
||||||
test('works with century years', () => {
|
test.skip('works with century years', () => {
|
||||||
expect(leapYears(1600)).toBe(true);
|
expect(leapYears(1600)).toBe(true);
|
||||||
});
|
});
|
||||||
test('works with century years', () => {
|
test.skip('works with century years', () => {
|
||||||
expect(leapYears(700)).toBe(false);
|
expect(leapYears(700)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
const convertToCelsius = function(deg) {
|
const convertToCelsius = function() {
|
||||||
return Math.round((deg - 32) * (5/9) * 10) / 10;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const convertToFahrenheit = function(deg) {
|
const convertToFahrenheit = function() {
|
||||||
return Math.round((deg * (9/5) + 32) * 10) / 10;
|
|
||||||
// x °C ≘ (x ×9/5+ 32) °F
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Do not edit below this line
|
// Do not edit below this line
|
||||||
|
|
|
@ -4,22 +4,22 @@ describe('convertToCelsius', () => {
|
||||||
test('works', () => {
|
test('works', () => {
|
||||||
expect(convertToCelsius(32)).toEqual(0);
|
expect(convertToCelsius(32)).toEqual(0);
|
||||||
});
|
});
|
||||||
test('rounds to 1 decimal', () => {
|
test.skip('rounds to 1 decimal', () => {
|
||||||
expect(convertToCelsius(100)).toEqual(37.8);
|
expect(convertToCelsius(100)).toEqual(37.8);
|
||||||
});
|
});
|
||||||
test('works with negatives', () => {
|
test.skip('works with negatives', () => {
|
||||||
expect(convertToCelsius(-100)).toEqual(-73.3);
|
expect(convertToCelsius(-100)).toEqual(-73.3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('convertToFahrenheit', () => {
|
describe('convertToFahrenheit', () => {
|
||||||
test('works', () => {
|
test.skip('works', () => {
|
||||||
expect(convertToFahrenheit(0)).toEqual(32);
|
expect(convertToFahrenheit(0)).toEqual(32);
|
||||||
});
|
});
|
||||||
test('rounds to 1 decimal', () => {
|
test.skip('rounds to 1 decimal', () => {
|
||||||
expect(convertToFahrenheit(73.2)).toEqual(163.8);
|
expect(convertToFahrenheit(73.2)).toEqual(163.8);
|
||||||
});
|
});
|
||||||
test('works with negatives', () => {
|
test.skip('works with negatives', () => {
|
||||||
expect(convertToFahrenheit(-10)).toEqual(14);
|
expect(convertToFahrenheit(-10)).toEqual(14);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue