solves 03_reverseString, 05_sumAll
This commit is contained in:
parent
e7847b0ac1
commit
6529b63f8e
|
@ -1,5 +1,9 @@
|
|||
const reverseString = function() {
|
||||
|
||||
const reverseString = function (str) {
|
||||
let newString = "";
|
||||
for (let i = str.length - 1; i >= 0; i--) {
|
||||
newString += str[i];
|
||||
}
|
||||
return newString;
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
const reverseString = require('./reverseString')
|
||||
const reverseString = require("./reverseString");
|
||||
|
||||
describe('reverseString', () => {
|
||||
test('reverses single word', () => {
|
||||
expect(reverseString('hello')).toEqual('olleh');
|
||||
describe("reverseString", () => {
|
||||
test("reverses single word", () => {
|
||||
expect(reverseString("hello")).toEqual("olleh");
|
||||
});
|
||||
|
||||
test.skip('reverses multiple words', () => {
|
||||
expect(reverseString('hello there')).toEqual('ereht olleh')
|
||||
})
|
||||
test("reverses multiple words", () => {
|
||||
expect(reverseString("hello there")).toEqual("ereht olleh");
|
||||
});
|
||||
|
||||
test.skip('works with numbers and punctuation', () => {
|
||||
expect(reverseString('123! abc!')).toEqual('!cba !321')
|
||||
})
|
||||
test.skip('works with blank strings', () => {
|
||||
expect(reverseString('')).toEqual('')
|
||||
})
|
||||
test("works with numbers and punctuation", () => {
|
||||
expect(reverseString("123! abc!")).toEqual("!cba !321");
|
||||
});
|
||||
test("works with blank strings", () => {
|
||||
expect(reverseString("")).toEqual("");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const removeFromArray = function() {
|
||||
|
||||
const removeFromArray = function (arr, ...args) {
|
||||
return arr.filter((x) => !args.includes(x));
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
const removeFromArray = require('./removeFromArray')
|
||||
const removeFromArray = require("./removeFromArray");
|
||||
|
||||
describe('removeFromArray', () => {
|
||||
test('removes a single value', () => {
|
||||
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,23 @@
|
|||
const sumAll = function() {
|
||||
const sumAll = function (num1, num2) {
|
||||
let sum = 0;
|
||||
|
||||
if (num1 > num2) {
|
||||
for (let i = num2; i <= num1; i++) {
|
||||
sum += i;
|
||||
}
|
||||
} else if (num1 < 0 || num2 < 0) {
|
||||
sum = "ERROR";
|
||||
} else if (typeof num1 != "number" || typeof num2 != "number") {
|
||||
sum = "ERROR";
|
||||
} else if (isNaN(num1) || isNaN(num2)) {
|
||||
sum = "ERROR";
|
||||
} else {
|
||||
for (let i = num1; i <= num2; i++) {
|
||||
sum += i;
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
};
|
||||
|
||||
// Do not edit below this line
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
const sumAll = require('./sumAll')
|
||||
const sumAll = require("./sumAll");
|
||||
|
||||
describe('sumAll', () => {
|
||||
test('sums numbers within the range', () => {
|
||||
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', () => {
|
||||
expect(sumAll(-10, 4)).toEqual('ERROR');
|
||||
test("returns ERROR with negative numbers", () => {
|
||||
expect(sumAll(-10, 4)).toEqual("ERROR");
|
||||
});
|
||||
test.skip('returns ERROR with non-number parameters', () => {
|
||||
expect(sumAll(10, "90")).toEqual('ERROR');
|
||||
test("returns ERROR with non-number parameters", () => {
|
||||
expect(sumAll(10, "90")).toEqual("ERROR");
|
||||
});
|
||||
test.skip('returns ERROR with non-number parameters', () => {
|
||||
expect(sumAll(10, [90, 1])).toEqual('ERROR');
|
||||
test("returns ERROR with non-number parameters", () => {
|
||||
expect(sumAll(10, [90, 1])).toEqual("ERROR");
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue