Ad
  • Custom User Avatar

    @benbrnpetit for larger datasets push will be more performant than unshifting. When you add an element to the end of an array, it can be done instantly. When you unshift and array, you must move the entire array forward, which takes more time with larger arrays of data

  • Custom User Avatar

    how? or this sarcasm?

  • Custom User Avatar

    Nice and simple solution) Cool!

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
  • Custom User Avatar

    may be a stupid question of a JS beginner but - why there is 'i < data.length' instead of 'i < data.length - 7'?

  • Custom User Avatar

    Nice use of spread syntax.

  • Custom User Avatar

    console.time() gives me around 0.115ms for both methods.

  • Custom User Avatar
  • Custom User Avatar

    from the end through the push will be faster

  • Custom User Avatar
  • Custom User Avatar

    This type of thing is often the best solution to a problem!

  • Custom User Avatar

    No worries, I can translate to haskell and ruby if you are looking for translations, just send me a message on gitter.

  • Custom User Avatar

    Thank you! I appreciate the advice very much. I'll try to think of a better way to make this problem something different (and I'll probably unpublish it if I can't, and work on something else of course).

  • Custom User Avatar

    johnoro,

    There are a lot of great people on CW who are open, friendly and very helpful. Don't let the few who are otherwise actually influence your decisions, just focus on the postive and ignore the rest.

    It isn't easy to avoid duplicates, especially if you are not a very experienced programmer because

    • you can't easily search for them
    • you maybe don't even realize they are duplicates

    There are lots of mathy things which have various names, and no one uses all of them in the description so it is easy to write a duplicate kata because no one used the same key words you used.

    There are also some users who will flag things as duplicates if you use the same general algorithm, but for a beginner, or even intermediate programmer that might not even be evident if you were to actually have the other kata in front of you.

    It might not be as much work as you think to republish/publish a kata because you can just use one as the starting point for another, and all the work you go into developing the test package makes the next one that much easier as you can save/reused parts.

    Reworking a kata often is pointless because if even you rework it, the up front heavy negative votes will keep it in Beta because users rarely come back to see if they should change their vote.

    The best way to actually avoid the duplicate charge is to actually come up with an original problem :

    • learn something new
    • try to frame it as a problem

    This is also the most beneficial for you as it really will cement it in your mind. However it is also the hardest and most involved kata to make, hence why it isn't that common. A lot of the kata are just restatements of problems found in algorithm books (minimum string distance, or come from other sites like project euler, etc.).

    If you are an avid blog reader it might be a source because people often talk about new things there and that can give you ideas which are not often published. But the ideal solution really is to see the writing process as just another way you learn, see the effort you make as being of benefit to you and not getting attached to the result of publishing / voting.

  • Loading more items...