-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove a val in arr and return the length of remaining values #10
base: master
Are you sure you want to change the base?
Conversation
bc4b1b1
to
3022832
Compare
const removeElement = require("./solution"); | ||
|
||
describe("remove element", () => { | ||
it("should remove an element and return its length", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also add a test to show that the array is mutated; coz how about if I just count the elements and return that count?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The length should be different/less.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, feedback taken and will work on it.
* but assigining its num values | ||
*/ | ||
if (arr[i] != val) { | ||
arr[counts++] = arr[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not correct, take an example:
arr = [1, 2, 4, 2, 5];
val = 2;
// when i = 0, arr[i] != val is true, so
// arr[counts++] = arr[i], basically arr[0] = arr[0], nothing has happened here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check on this.
@profnandaa almost similar to #9 as suggested in Leetcode.
You can also check on this one if you get some time.
Thanks.