This commit is contained in:
parent
0747078d97
commit
cd1fec690f
|
@ -1,5 +1,18 @@
|
|||
const removeFromArray = function() {
|
||||
// [1, 2, 3, 4], 3, 2)).toEqual([1, 4])
|
||||
|
||||
const removeFromArray = function(arr, ...nums) {
|
||||
|
||||
let array = [];
|
||||
// iterate over array
|
||||
for (let i = 0; i<arr.length; i++){
|
||||
// iterate over nums
|
||||
for (let j = 0; j<nums.length; j++){
|
||||
if(nums.includes(arr[i]) === false && array.includes(arr[i]) === false ){
|
||||
array.push(arr[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
return array
|
||||
};
|
||||
|
||||
// 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,4 +1,31 @@
|
|||
const sumAll = function() {
|
||||
const sumAll = function(int1, int2) {
|
||||
let intsToAdd = [int1, int2]
|
||||
let smallNum = int1;
|
||||
let bigNum = int2;
|
||||
let sum = 0;
|
||||
|
||||
|
||||
for (let i = 0; i < intsToAdd.length; i++){
|
||||
if(typeof(int1) === 'number' && typeof(int2) === 'number' && intsToAdd[i] > 0){
|
||||
if(intsToAdd[i] >= bigNum && intsToAdd[i] >= smallNum){
|
||||
bigNum = intsToAdd[i]
|
||||
} else{
|
||||
smallNum = intsToAdd[i]
|
||||
}
|
||||
}else {
|
||||
return 'ERROR'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(let range = smallNum; range <= bigNum; range++){
|
||||
sum = range + sum
|
||||
}
|
||||
if (sum > 0){
|
||||
return sum
|
||||
} else {
|
||||
return "ERROR"
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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 % 400 == 0 || year % 4 == 0 && year % 100 != 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,9 +1,15 @@
|
|||
const ftoc = function() {
|
||||
|
||||
const ftoc = function(tempF) {
|
||||
// [°C] = ([°F] − 32) × 5⁄9
|
||||
let fToC = ((tempF - 32.0) * (5/9))
|
||||
let fixed = fToC.toFixed(1)
|
||||
return parseFloat(fixed)
|
||||
};
|
||||
|
||||
const ctof = function() {
|
||||
|
||||
const ctof = function(tempC) {
|
||||
// [°F] = [°C] × 9⁄5 + 32
|
||||
let cToF = ((tempC * (9/5)) + 32.0)
|
||||
let fixed = cToF.toFixed(1)
|
||||
return parseFloat(fixed)
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
|
|
|
@ -4,22 +4,22 @@ describe('ftoc', () => {
|
|||
test('works', () => {
|
||||
expect(ftoc(32)).toEqual(0);
|
||||
});
|
||||
test.skip('rounds to 1 decimal', () => {
|
||||
test('rounds to 1 decimal', () => {
|
||||
expect(ftoc(100)).toEqual(37.8);
|
||||
});
|
||||
test.skip('works with negatives', () => {
|
||||
test('works with negatives', () => {
|
||||
expect(ftoc(-100)).toEqual(-73.3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ctof', () => {
|
||||
test.skip('works', () => {
|
||||
test('works', () => {
|
||||
expect(ctof(0)).toEqual(32);
|
||||
});
|
||||
test.skip('rounds to 1 decimal', () => {
|
||||
test('rounds to 1 decimal', () => {
|
||||
expect(ctof(73.2)).toEqual(163.8);
|
||||
});
|
||||
test.skip('works with negatives', () => {
|
||||
test('works with negatives', () => {
|
||||
expect(ctof(-10)).toEqual(14);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,25 +1,41 @@
|
|||
const add = function() {
|
||||
|
||||
const add = function(x,y) {
|
||||
return x + y
|
||||
};
|
||||
|
||||
const subtract = function() {
|
||||
|
||||
const subtract = function(x,y) {
|
||||
return x - y
|
||||
};
|
||||
|
||||
const sum = function() {
|
||||
|
||||
const sum = function(nums) {
|
||||
let sum = 0;
|
||||
nums.forEach(num => {
|
||||
sum = num + sum
|
||||
});
|
||||
return sum
|
||||
};
|
||||
|
||||
const multiply = function() {
|
||||
|
||||
const multiply = function(nums) {
|
||||
let result = 1;
|
||||
nums.forEach(num => {
|
||||
result = num * result
|
||||
});
|
||||
return result
|
||||
};
|
||||
|
||||
const power = function() {
|
||||
|
||||
const power = function(x , y) {
|
||||
let result = x;
|
||||
for(i = 1; i < y; i++){
|
||||
result = x * result
|
||||
}
|
||||
return result
|
||||
};
|
||||
|
||||
const factorial = function() {
|
||||
|
||||
const factorial = function(x) {
|
||||
let result = 1
|
||||
for(let i = 1; i <= x; i++){
|
||||
result = result * i
|
||||
}
|
||||
return result
|
||||
};
|
||||
|
||||
// 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);
|
||||
});
|
||||
});
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue