Solution
This commit is contained in:
parent
2e51715036
commit
987514c255
|
@ -1,5 +1,8 @@
|
|||
const removeFromArray = function() {
|
||||
const removeFromArray = function(array, ...args) {
|
||||
|
||||
const newArray = [];
|
||||
|
||||
return array.filter(val => !args.includes(val));
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
|
|
|
@ -4,22 +4,22 @@ describe('removeFromArray', () => {
|
|||
test('removes a single value', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]);
|
||||
});
|
||||
test.skip('removes multiple values', () => {
|
||||
test('removes multiple values', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]);
|
||||
});
|
||||
test.skip('ignores non present values', () => {
|
||||
test('ignores non present values', () => {
|
||||
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]);
|
||||
});
|
||||
test.skip('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]);
|
||||
});
|
||||
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,29 @@
|
|||
const sumAll = function() {
|
||||
const sumAll = function(first, second) {
|
||||
|
||||
if (first < 0 || second < 0) {
|
||||
return 'ERROR';
|
||||
} else if (!Number.isInteger(first)) {
|
||||
return 'ERROR';
|
||||
} else if (!Number.isInteger(second)) {
|
||||
return 'ERROR';
|
||||
} else if (first <= second){
|
||||
|
||||
let sum = 0;
|
||||
|
||||
for (let i = first; i <= second; i++) {
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
|
||||
} else if (first > second) {
|
||||
|
||||
let sum = 0;
|
||||
|
||||
for (let i = first; i >= second; 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,9 @@
|
|||
const leapYears = function() {
|
||||
|
||||
const leapYears = function(year) {
|
||||
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
|
||||
return true;
|
||||
} else {
|
||||
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,17 @@
|
|||
const convertToCelsius = function() {
|
||||
const convertToCelsius = function(fahrenheit) {
|
||||
|
||||
let celsius = (fahrenheit - 32 ) * 5 / 9;
|
||||
celsius = parseFloat(celsius.toFixed(1));
|
||||
return celsius;
|
||||
|
||||
};
|
||||
|
||||
const convertToFahrenheit = function() {
|
||||
const convertToFahrenheit = function(celsius) {
|
||||
|
||||
let fahrenheit = (celsius * 9 / 5) + 32;
|
||||
fahrenheit = parseFloat(fahrenheit.toFixed(1));
|
||||
return fahrenheit;
|
||||
|
||||
};
|
||||
|
||||
// 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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,25 +1,73 @@
|
|||
const add = function() {
|
||||
const add = function(a, b) {
|
||||
|
||||
return a + b;
|
||||
|
||||
};
|
||||
|
||||
const subtract = function() {
|
||||
const subtract = function(a, b) {
|
||||
|
||||
return a - b;
|
||||
|
||||
};
|
||||
|
||||
const sum = function() {
|
||||
const sum = function(array) {
|
||||
|
||||
let suma = 0;
|
||||
|
||||
if (array.length == 0) {
|
||||
|
||||
return 0;
|
||||
|
||||
} else {
|
||||
|
||||
array.forEach(item => {
|
||||
suma += item
|
||||
});
|
||||
|
||||
return suma;
|
||||
}
|
||||
};
|
||||
|
||||
const multiply = function(array) {
|
||||
|
||||
let product = 1;
|
||||
|
||||
if (array.length == 0) {
|
||||
|
||||
return 0;
|
||||
|
||||
} else {
|
||||
|
||||
array.forEach(item => {
|
||||
product *= item;
|
||||
});
|
||||
|
||||
return product;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const multiply = function() {
|
||||
const power = function(a, b) {
|
||||
|
||||
return Math.pow(a, b);
|
||||
|
||||
};
|
||||
|
||||
const power = function() {
|
||||
const factorial = function(a) {
|
||||
|
||||
};
|
||||
if (a < 0) {
|
||||
|
||||
const factorial = function() {
|
||||
return -1;
|
||||
|
||||
} else if (a == 0) {
|
||||
|
||||
return 1;
|
||||
|
||||
} else {
|
||||
|
||||
return a * factorial(a - 1);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
|
|
|
@ -5,73 +5,73 @@ describe('add', () => {
|
|||
expect(calculator.add(0,0)).toBe(0);
|
||||
});
|
||||
|
||||
test.skip('adds 2 and 2', () => {
|
||||
test('adds 2 and 2', () => {
|
||||
expect(calculator.add(2,2)).toBe(4);
|
||||
});
|
||||
|
||||
test.skip('adds positive numbers', () => {
|
||||
test('adds positive numbers', () => {
|
||||
expect(calculator.add(2,6)).toBe(8);
|
||||
});
|
||||
});
|
||||
|
||||
describe('subtract', () => {
|
||||
test.skip('subtracts numbers', () => {
|
||||
test('subtracts numbers', () => {
|
||||
expect(calculator.subtract(10,4)).toBe(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe('sum', () => {
|
||||
test.skip('computes the sum of an empty array', () => {
|
||||
test('computes the sum of an empty array', () => {
|
||||
expect(calculator.sum([])).toBe(0);
|
||||
});
|
||||
|
||||
test.skip('computes the sum of an array of one number', () => {
|
||||
test('computes the sum of an array of one number', () => {
|
||||
expect(calculator.sum([7])).toBe(7);
|
||||
});
|
||||
|
||||
test.skip('computes the sum of an array of two numbers', () => {
|
||||
test('computes the sum of an array of two numbers', () => {
|
||||
expect(calculator.sum([7,11])).toBe(18);
|
||||
});
|
||||
|
||||
test.skip('computes the sum of an array of many numbers', () => {
|
||||
test('computes the sum of an array of many numbers', () => {
|
||||
expect(calculator.sum([1,3,5,7,9])).toBe(25);
|
||||
});
|
||||
});
|
||||
|
||||
describe('multiply', () => {
|
||||
test.skip('multiplies two numbers', () => {
|
||||
test('multiplies two numbers', () => {
|
||||
expect(calculator.multiply([2,4])).toBe(8);
|
||||
});
|
||||
|
||||
test.skip('multiplies several numbers', () => {
|
||||
test('multiplies several numbers', () => {
|
||||
expect(calculator.multiply([2,4,6,8,10,12,14])).toBe(645120);
|
||||
});
|
||||
});
|
||||
|
||||
describe('power', () => {
|
||||
test.skip('raises one number to the power of another number', () => {
|
||||
test('raises one number to the power of another number', () => {
|
||||
expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64
|
||||
});
|
||||
});
|
||||
|
||||
describe('factorial', () => {
|
||||
test.skip('computes the factorial of 0', () => {
|
||||
test('computes the factorial of 0', () => {
|
||||
expect(calculator.factorial(0)).toBe(1); // 0! = 1
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 1', () => {
|
||||
test('computes the factorial of 1', () => {
|
||||
expect(calculator.factorial(1)).toBe(1);
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 2', () => {
|
||||
test('computes the factorial of 2', () => {
|
||||
expect(calculator.factorial(2)).toBe(2);
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 5', () => {
|
||||
test('computes the factorial of 5', () => {
|
||||
expect(calculator.factorial(5)).toBe(120);
|
||||
});
|
||||
|
||||
test.skip('computes the factorial of 10', () => {
|
||||
test('computes the factorial of 10', () => {
|
||||
expect(calculator.factorial(10)).toBe(3628800);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,32 @@
|
|||
const palindromes = function () {
|
||||
const palindromes = function (string) {
|
||||
|
||||
const array = string.split("");
|
||||
const newArray = [];
|
||||
const reversedArray = [];
|
||||
let newString = "";
|
||||
let reversedString = "";
|
||||
|
||||
array.forEach(item =>
|
||||
{
|
||||
// verific daca este litera
|
||||
if (item.toLowerCase() != item.toUpperCase()) {
|
||||
newArray.push(item);
|
||||
reversedArray.unshift(item);
|
||||
}
|
||||
|
||||
newString = newArray.join("").toLowerCase();
|
||||
reversedString = reversedArray.join("").toLowerCase();
|
||||
});
|
||||
|
||||
if (newString == reversedString) {
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
|
|
|
@ -4,22 +4,22 @@ describe('palindromes', () => {
|
|||
test('works with single words', () => {
|
||||
expect(palindromes('racecar')).toBe(true);
|
||||
});
|
||||
test.skip('works with punctuation ', () => {
|
||||
test('works with punctuation ', () => {
|
||||
expect(palindromes('racecar!')).toBe(true);
|
||||
});
|
||||
test.skip('works with upper-case letters ', () => {
|
||||
test('works with upper-case letters ', () => {
|
||||
expect(palindromes('Racecar!')).toBe(true);
|
||||
});
|
||||
test.skip('works with multiple words', () => {
|
||||
test('works with multiple words', () => {
|
||||
expect(palindromes('A car, a man, a maraca.')).toBe(true);
|
||||
});
|
||||
test.skip('works with multiple words', () => {
|
||||
test('works with multiple words', () => {
|
||||
expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe(true);
|
||||
});
|
||||
test.skip('doesn\'t just always return true', () => {
|
||||
test('doesn\'t just always return true', () => {
|
||||
expect(palindromes('ZZZZ car, a man, a maracaz.')).toBe(false);
|
||||
});
|
||||
test.skip('works with numbers in a string', () => {
|
||||
test('works with numbers in a string', () => {
|
||||
expect(palindromes('rac3e3car')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue