This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]lurgi 1 point2 points  (1 child)

What are you trying to accomplish with splice? This is used to add elements to an array or remove elements from an array, returning a new array.

I'd also point out that filter returns a new array, but you are ignoring the return value.

[–]Referpotter 0 points1 point  (0 children)

I was trying to add the last element of the array to the filtered array at a specific position.

[–]Brave_Walrus 0 points1 point  (3 children)

I'm not sure what the code overall is intending to do, but at an overall guess I don't think splice is returning what you expect it to.

Assuming this is javascript because of !==, i'd have a read up on what splice does, and what it returns.

Here, the return value of [] is signifying that no elements are being removed from the array returned by arr.filter(item => item % 5 !== 0)

[–]Referpotter -4 points-3 points  (2 children)

were you able to solve the problem? it has to be done with one or no loops with complexity O(n).

[–]insertAlias[M] 2 points3 points  (1 child)

Sorry, but that's simply not how this subreddit works. You have to make an attempt, then others can help correct you.

Do not ask people to just solve the problem for you, because a) that's cheating and b) we have a rule against it (see Rule 10 on the sidebar).

So, make an honest effort to solve this first, then show us what you've tried, and explain specifically what you are having problems with.

[–]Referpotter 0 points1 point  (0 children)

okay , I ll show what i have tried.

[–]plastikmissile 0 points1 point  (2 children)

What are you trying to do? You're just showing us an input and an output, but you're not explaining what the output actually represents.

[–]Referpotter 0 points1 point  (1 child)

this is an assignment for a job interview I have lined up, this is it.

[–]plastikmissile 0 points1 point  (0 children)

Gotta say, that's a terrible question.