Retired
splicing (retired)
1,091 of 1,100xerxes
Loading description...
Fundamentals
Arrays
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
There are lots of good case to use
splice
.For example, remove or replace some items in specific index.
But you choose the one, that remove multi specific items?
You're not even enforcing the use of
splice
.Check this solution out, as well as my own solution.
This kata is terrible by design. There's no point in using a method modifying the array AND returning the same array as the result of the operation (on success the result is an array, but on failure it's boolean - great idea). Because of this senseless decision
filter
is also forbidden as "it allows you to solve the task in a way that was not intended" (this is not even mentioned in the description).Please add random tests.
Hi, I've added a CoffeeScript translation, if you want to approve it, instructions for the approval process are here.
I've never used CoffeeScript before, but I trust that you've tested it so I'll be happy to add your translation. Wow, I haven't been on Codewars for a few months, but I'm glad to see so many people liked the kata.
Wow that last test really had me stumped, good kata.
This comment has been hidden.
The index keeps on running without any knowledge about the spliced array. It will therefore jump over some of the elements in the array.
This comment has been hidden.
Description says :
This comment has been hidden.
When you remove element from the beginning (or from the middle) every element on the right is shifted to the left by one. Then you continue your loop but all the indexes on the right are messed up. Try starting from the right side.
This comment has been hidden.
I don't like this kata as well. Forcing to use splice when filter is clearly a better way of doing.
I'm fine with forcing to use a function, but only and only in a kata where the function is the best solution. And same as Poring: return 2 possible types of object is not good.
I don't like this kata. It promotes bad code.
Extending global objects is usually a bad idea.
Having inconsistent return values (
array
vsfalse
) is a really bad idea.The absolute worst part is the w3schools link at the end, though.
How do I downvote a kata?
If you do not want us to use filter, you should disable filter:
Array.prototype.filter = function () { throw new Error("I told you not to use filter. Did you listen? No. You did not listen. FAIL."); };
Or just make it not actually filter out any of the elements:
Array.prototype.filter = function () { return this.slice(); };
"(Note: It is possible to pass this kata using .filter(), but the point is to use .splice())"
If the point is to use splice() instead of filter(), then you need to disable filter(). IMHO you either need to do that, or modify the description but add some test cases.
If the intention of this kata is to use splice instead of filter, couldn't you just disable filter?
I would change the kata description. It is said that when the empty array is passed or array without value to remove. I was confused, because the function is passed only one argument to remove - and it could be an empty array (for example You want to remove empty array from arrays of array). You do not pass the array, because this function is member of the array. So I would just change the description to "If the array is empty or has no element to remove". The "passing" word is just confusing in my opinion. Thanks for kata :)
Thank you for the help. I have now changed the description to be less confusing.
I fail to understand why false should be returned "sometimes" while a reduced array at other times.
It would make more sense to return number of items removed - making return value more consistent.
Sorry about that, I was editing the test fixture and accidentaly messed it up.
This comment has been hidden.
This comment has been hidden.
It could be passed without using splice.
Negative test case isn't present. Code, which uses filter method passes.
You have a typo in your example test case, there's a square bracket (
[
) where there should be an open parentheses ((
).(Also, in my opinion, it doesn't make sense to have the function return the array, since
splice
modifies the array directly. But that's not a big issue.)Finally, you should add a few more test cases, especially edge cases (empty arrays and arrays that don't contain the value being removed), and randomized tests, making "cheating" more difficult.
And, on a less relevent point, your one set of array values is a little immature. If you care, you'll most likely get more support (upvotes) by having better values.