Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions solutions/33.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Maricris Bonzo: @seemcat
// create a function that takes in an array and a number
// and returns an array without that number

const solution = (arr, num) => {
let i = 0;
let newArr = [];
while (i < arr.length) {
if (num !== arr[i]) {
newArr.push(arr[i]);
i++;
} else {
i++;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seemcat you can condense this as:
while (i < arr.length) { if (num !== arr[i]) { newArr.push(arr[i]); } i++; }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seemcat this change needs to be made.

return newArr;
};

module.exports = {
solution
};
15 changes: 15 additions & 0 deletions test/33.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const expect = require('chai').expect;
let solution = require('../solutions/33').solution;
// solution = require('./yourSolution').solution;

describe('array without a number', () => {
it('array [1,2,3,2,2,3] without 2 is [1,3,3]', () => {
expect(solution([1,2,3,2,2,3],2)).eql([1,3,3]);
})
it('array [1,2,3,2,2,3] without 3 is [1,2,2,2]', () => {
expect(solution([1,2,3,2,2,3],3)).eql([1,2,2,2]);
})
it('array [1,2,3,2,2,3] without 1 is [2,3,2,2,3]', () => {
expect(solution([1,2,3,2,2,3],1)).eql([2,3,2,2,3]);
})
});