Retired

splicing (retired)

1,091 of 1,100xerxes
Description
Loading description...
Fundamentals
Arrays
  • Please sign in or sign up to leave a comment.
  • max30272 Avatar

    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?

  • WestwardLand968 Avatar

    You're not even enforcing the use of splice.

    Check this solution out, as well as my own solution.

  • FArekkusu Avatar

    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).

  • siebenschlaefer Avatar

    Please add random tests.

  • JoshSchreuder Avatar

    Hi, I've added a CoffeeScript translation, if you want to approve it, instructions for the approval process are here.

  • ma3east Avatar

    Wow that last test really had me stumped, good kata.

  • Zazen Avatar

    This comment has been hidden.

  • sohilpandya Avatar

    This comment has been hidden.

  • raunaqrox Avatar

    This comment has been hidden.

  • BoogerKlown Avatar

    This comment has been hidden.

  • IVBakker Avatar

    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.

  • Poring Avatar

    I don't like this kata. It promotes bad code.

    • Extending global objects is usually a bad idea.

    • Having inconsistent return values (array vs false) is a really bad idea.

  • joeframbach Avatar

    How do I downvote a kata?

  • computerguy103 Avatar

    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(); };

  • Arheus Avatar

    "(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.

  • soldier-b Avatar

    If the intention of this kata is to use splice instead of filter, couldn't you just disable filter?

  • baaart Avatar

    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 :)

  • christianhammer Avatar

    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.

  • xerxes Avatar

    Sorry about that, I was editing the test fixture and accidentaly messed it up.

  • riomus Avatar

    This comment has been hidden.

  • robin-garnham Avatar

    This comment has been hidden.

  • cepe Avatar

    It could be passed without using splice.

    Negative test case isn't present. Code, which uses filter method passes.

  • OverZealous Avatar

    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.