tests ✅ pass removeArray, [solution looked]
This commit is contained in:
parent
b151f4e87f
commit
7e9ec5f434
|
@ -1,5 +1,20 @@
|
|||
const removeFromArray = function() {
|
||||
const removeFromArray = function (array, ...args) {
|
||||
|
||||
/*
|
||||
- Array is used to filter over each number
|
||||
- Each number is compared to the ...args Array
|
||||
- If there is no match between Number and args Array, we push that number
|
||||
[I checked solution: did not know includes excisted, and re-ording of it]
|
||||
*/
|
||||
|
||||
var newArray = [];
|
||||
array.filter(function (number) {
|
||||
if (!args.includes(number)) {
|
||||
newArray.push(number)
|
||||
}
|
||||
})
|
||||
|
||||
return newArray
|
||||
};
|
||||
|
||||
// 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]);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue