7 kyu

Default + Rest + Spread

Description
Loading description...
Refactoring
  • Please sign in or sign up to leave a comment.
  • JohanWiltink Avatar

    Fixed tests allow my solution, where Rest is, I think, not what was intended, but works because the tests happen to work for it.

    No random tests.

    Fixed tests are overly limited, simplistic, and pass correct solutions instead of trying to break incorrect ones.

    defaultExample(3,7) -> 10 should have any argument but 7 in second place.

    restExample should have tests with the second argument not accidentally always the correct length.

    spreadExample(...[1,2,3]) is literally just spreadExample(1,2,3) ( except less efficient ). Those tests should have a varying number of arguments.

  • farhanaditya Avatar

    Description's block code markdown is broken.

  • Yanzhan Avatar

    ES6 makes my life easier.

  • donaldsebleung Avatar

    Good Kata :) Instructions are simple and unambiguous. (Kata) Requires a tiny bit of thinking.

    I personally think this Kata is ready for approval and that it should be ranked as 7kyu.

  • somethinghere Avatar

    Good Kata! I have noticed some people are cheating on the rest parameters, just filling in 'x,y,z' as per the test cases; it might be better to use some variation on test cases so people can't directly use that cheat (and they would have to use a lot more code if they want to filter out the amount of arguments, OR use rest parameters).

  • CIS 122 Avatar

    Nice educational kata! One suggestion: the convention in JavaScript is to use lowerCamelCase for variable and function names, so Default, Rest, and Spread should be default, rest, and spread. You use lowerCamelCase in the examples, but UpperCamelCase in the actual code, which is odd.

    • matt c Avatar

      The reason for that is in javascript you can't use default as a function e.g.

      function default() { }
      

      will throw an error because default is a keyword used in switch/case statements so I thought I'll keep them all the same if that's okay?

      (Didn't mean to resolve if you had another idea)

      Suggestion marked resolved by matt c 10 years ago
    • CIS 122 Avatar

      I suggest naming them defaultExample, restExample, and spreadExample, and then you can also add the code:

      defaultExample = defaultExample || Default;
      restExample = restExample || Rest;
      spreadExample = spreadExample || Spread;
      

      above your test cases so that you don't invalidate any of the existing correct solutions (if you care about that, which you don't necessarily need to).

    • matt c Avatar

      That causes a Reference error for solutions that use the old method names

    • CIS 122 Avatar

      You're right, here's the correct code:

      // For backwards compatibility on existing solutions
      defaultExample = (typeof defaultExample === 'undefined') ? Default : defaultExample;
      restExample = (typeof restExample === 'undefined') ? Rest : restExample;
      spreadExample = (typeof spreadExample === 'undefined') ? Spread : spreadExample;
      

      I've gone ahead and made the change as a contributor. I hope that's not stepping on your toes. If you don't like the change, just let me know and I'll change it back to the original version.

    • matt c Avatar

      That's all fine, thanks for your input. We're here to help the community anyway :)

    • CIS 122 Avatar

      Well, I thought it was a really great and useful kata, so I wanted to help!

  • JoshSchreuder Avatar

    Like other comments, I found the description a little too vague - I think it needs to be super clear (preferably before the theory explanation) that the aim is to alter the function bodies to pass the existing tests.

    Mainly because this type of exercise is a little different to just about every other kata which has a defined goal and the test cases are just used to verify the goal, rather than the test cases being the goal itself.

    I did like the explanation of the ES6 features though so well done!

  • ubaw Avatar

    expected value from second test case from "Rest" is correct?

    • matt c Avatar

      yes for example if you had a function like this

      myFunction(a, b, ...c) {
        return (a + b) * c.length;
      }
      myFunction(1, 2, 3, 4, 5) // 9
      

      This is because a = 1, b = 2 but the rest of the arguments are concatenated into an array so c = [3, 4, 5]. since the return statement is (a + b) * c.length it basically stands for (1 + 2) * 3 hence the answer as 9. Hope this makes sence, good luck

  • Abbe Avatar

    There still is a missing { in the start of the Spread function.

    • matt c Avatar

      Very sorry, thought I fixed it, Please mark issue as resolved if I have.

    • matt c Avatar

      I'm marking as resolved because I believe I've fixed the issue and you haven't changed issue status in 3 weeks, thanks :)

      Issue marked resolved by matt c 10 years ago
    • Abbe Avatar

      Very sorry. I must have missed your answer.

      Good that you decided to mark it as resolved yourself! :-)

  • OverZealous Avatar

    This kata needs a much better description, and/or better setup code.

    • matt c Avatar

      Yes it deffinitly does, I will update it as soon as I can. Sorry I missed it

    • matt c Avatar

      Please mark this issue as resolved if you think the description is better, and if you believe the setup code could be better could you post an example, thank you!

    • sayfidz Avatar

      You could either explain what each function is supposed to do or, if part of the challenge is to figure that out, at the end of the description say: "Using the indicated feature, implement a function that achieves the following results:" Then copy the test cases into the description.

      Also Spread needs a {.

    • matt c Avatar

      have I not done that?

    • sayfidz Avatar

      The directive to "complete the three functions" seems vague to me. Once I begin the kata, I can infer from the default test cases what the functions should do, but from the description I don't get a very clear picture of what the problem is and what I need to do to solve it.

    • matt c Avatar

      I do not see how someone could not understand that, I'm sorry there are plenty examples of how it's done and the test cases can be refered to if they are suck...

      Issue marked resolved by matt c 10 years ago
    • andrewferk Avatar

      Is reverse engineering the requirements part of this kata?

    • matt c Avatar

      The requirement of the kata is to complete the test cases, it is also an oppertunity to follow the new features of ES6 javascript which will help solve this kata easier, lots of examples in the description.