Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ezkemboi
Copy link
Member

@ezkemboi ezkemboi commented Feb 18, 2020

@profnandaa almost similar to #9 as suggested in Leetcode.
You can also check on this one if you get some time.
Thanks.

const removeElement = require("./solution");

describe("remove element", () => {
it("should remove an element and return its length", () => {

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?

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.

Copy link
Member Author

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]

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

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants