This commit is contained in:
npittard 2022-05-25 19:59:36 -04:00
parent 0747078d97
commit cd1fec690f
11 changed files with 7610 additions and 60 deletions

View File

@ -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 // Do not edit below this line

View File

@ -4,22 +4,22 @@ describe('removeFromArray', () => {
test('removes a single value', () => { test('removes a single value', () => {
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]); 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]); 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]); 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]); 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([]); 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"]); 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]); expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]);
}); });
}); });

View File

@ -1,5 +1,32 @@
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"
}
}; };
// Do not edit below this line // Do not edit below this line

View File

@ -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.skip('works with large numbers', () => { test('works with large numbers', () => {
expect(sumAll(1, 4000)).toEqual(8002000); 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); 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'); 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'); 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'); expect(sumAll(10, [90, 1])).toEqual('ERROR');
}); });
}); });

View File

@ -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 // Do not edit below this line

View File

@ -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.skip('works with non century years', () => { test('works with non century years', () => {
expect(leapYears(1997)).toBe(false); 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); expect(leapYears(34992)).toBe(true);
}); });
test.skip('works with century years', () => { test('works with century years', () => {
expect(leapYears(1900)).toBe(false); expect(leapYears(1900)).toBe(false);
}); });
test.skip('works with century years', () => { test('works with century years', () => {
expect(leapYears(1600)).toBe(true); expect(leapYears(1600)).toBe(true);
}); });
test.skip('works with century years', () => { test('works with century years', () => {
expect(leapYears(700)).toBe(false); expect(leapYears(700)).toBe(false);
}); });
}); });

View File

@ -1,9 +1,15 @@
const ftoc = function() { const ftoc = function(tempF) {
// [°C] = ([°F] 32) × 59
let fToC = ((tempF - 32.0) * (5/9))
let fixed = fToC.toFixed(1)
return parseFloat(fixed)
}; };
const ctof = function() { const ctof = function(tempC) {
// [°F] = [°C] × 95 + 32
let cToF = ((tempC * (9/5)) + 32.0)
let fixed = cToF.toFixed(1)
return parseFloat(fixed)
}; };
// Do not edit below this line // Do not edit below this line

View File

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

View File

@ -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 // Do not edit below this line

View File

@ -5,73 +5,73 @@ describe('add', () => {
expect(calculator.add(0,0)).toBe(0); 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); expect(calculator.add(2,2)).toBe(4);
}); });
test.skip('adds positive numbers', () => { test('adds positive numbers', () => {
expect(calculator.add(2,6)).toBe(8); expect(calculator.add(2,6)).toBe(8);
}); });
}); });
describe('subtract', () => { describe('subtract', () => {
test.skip('subtracts numbers', () => { test('subtracts numbers', () => {
expect(calculator.subtract(10,4)).toBe(6); expect(calculator.subtract(10,4)).toBe(6);
}); });
}); });
describe('sum', () => { describe('sum', () => {
test.skip('computes the sum of an empty array', () => { test('computes the sum of an empty array', () => {
expect(calculator.sum([])).toBe(0); 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); 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); 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); expect(calculator.sum([1,3,5,7,9])).toBe(25);
}); });
}); });
describe('multiply', () => { describe('multiply', () => {
test.skip('multiplies two numbers', () => { test('multiplies two numbers', () => {
expect(calculator.multiply([2,4])).toBe(8); 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); expect(calculator.multiply([2,4,6,8,10,12,14])).toBe(645120);
}); });
}); });
describe('power', () => { 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 expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64
}); });
}); });
describe('factorial', () => { describe('factorial', () => {
test.skip('computes the factorial of 0', () => { test('computes the factorial of 0', () => {
expect(calculator.factorial(0)).toBe(1); // 0! = 1 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); 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); 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); 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); expect(calculator.factorial(10)).toBe(3628800);
}); });
}); });

7492
package-lock.json generated

File diff suppressed because it is too large Load Diff