Ad
  • Default User Avatar

    what about this ?

    The entries() method of Map instances returns a new map iterator object that contains the [key, value] pairs for each element in this map in insertion order.

  • Custom User Avatar

    This just barely passes the "cpu playing against itself" tests, but has a few known bugs:

    • it's unclear how to handle the win message should the player win with the move provided by the cpu
    • it's unclear if CPU and player permanently switch signs when the CPU provides a player move or if the method should force the next move() call to be for the CPU
    • it's possible for the player to perform two moves by providing a move after the CPU picked one for the player already
  • Custom User Avatar

    Next time I would prefer that instead of relying on implementation details such as ordered dicts/Maps you simply provide an array of tuplies (i.e. the result of functions.entries() in JS). the V8 engine happens to also have ordered Maps and Sets, but that is not guranteed to happen in other JS engines.

  • Custom User Avatar

    for anyone solving this currently and confused by this edgecase: The solver appears to expect the output array to grow by at least 2 on each iteration, so if your result is an empty array after trimming leading and trailing zeroes you can create a new array of list.length + 2 and fill it with zeroes.

  • Custom User Avatar

    This kata very badly needs to be updated, there are no tests anymore and while the description asks for a "generator" it does not actually mean generator functions which now exist in JavaScript.

  • Custom User Avatar

    I'd like to add that this should in theory be using a linked list instead of an array, since it's having to re-index the array on every yield, which becomes a lot of work for large sequence sizes (like the pointless sequence test). Didn't time out here, so I guess array is acceptable :)

  • Custom User Avatar

    technically creates extra numbers, but I like how small this solution is without becoming an unreadable nightmare like 99% of the "best" solutions on here. Great work!

  • Custom User Avatar

    While trying to debug my solution I managed to find out that codewars allows for the injection of arbitary HTML via console.log. At least it removes script tags, so there's no immediatly obvious XSS vulnerability here. Still super annoying since it means I'll need to sanitize my own logs now.

    For reference here is the log function I used for debugging my solution:

    function ___log(text) {
      console.log(text.replace(/["'<>&]/gi, c => `&#${c.charCodeAt(0)};`));
    }
    
  • Custom User Avatar

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

  • Custom User Avatar

    Not going to lie, I am not going to bother with these Kata simply because there is no description. I am here to practice problem solving and implementing solutions and not play a guessing game.

  • Custom User Avatar

    In theory this is the best practice because it makes use of existing and tested code that's clearly available here.

  • Custom User Avatar

    Hi! Thanks for the replies. Yes, I did try looking through the documentation online. I saw a few different ways of approaching the problem, but some of them involved code that I haven't learned about yet. I tried rearranging my if/else if statements and that did the trick...

  • Custom User Avatar

    Have you tried to search for documentation online? Just something like "check empty array JavaScript", "check null array JavaScript"?

  • Custom User Avatar

    JavaScript Completions 20381

    You're doing it wrong. Try reading the posts below.

    P.S.: your current code works.

  • Custom User Avatar
  • Loading more items...