Ad
  • Custom User Avatar

    Omg, such a nice decision, thx for comments it helped me to understand how it works!)

  • Custom User Avatar

    I love this problem

  • Default User Avatar

    Maybe, the fact that it mutates the original array doesn't make it best practice

  • Custom User Avatar

    Sorry, what's the point of this comment? Why are you claiming the solution isn't feasible while it clearly is (as evident by it having passed all test cases) and telling us to do the auditing instead of giving the measured performance backing your claims? Your code provided in this comment isn't even a good way to benchmark - see Vyacheslav Egorov's presentation on performance and benchmarking to learn more on how performance tests can be useful but are prone to inaccuracy especially when ignoring engine optimizations.

    array=Array(100).fill(0).map(()=>Array(100).fill(0));
    console.log(snail(array))
    
    Real time: 0.093 s
    User time: 0.076 s
    Sys. time: 0.017 s
    CPU share: 99.58 %
    Exit code: 0
    

    (benchmarked and averaged over 100 unique instances of nodejs)

    This code runs faster than even your own code submitted for this kata, which yielded the following benchmarks (also averaged over 100 unique instances of nodejs):

    Real time: 0.104 s
    User time: 0.082 s
    Sys. time: 0.021 s
    CPU share: 99.30 %
    Exit code: 0
    
  • Custom User Avatar

    While this solution is easier to implement (which is genius, to be honest), it's not feasible based on time complexity.

    You can use this code to compare this function with other implementations for comparison:

    const runPrimePerformance = (...arguments) => 
    {
        for (let i=0; i < arguments.length; i++) {
            console.time(arguments[i].name);
            arguments[i](/*insert matrix here*/);
            console.timeEnd(arguments[i].name);
        }
    }
    runPrimePerformance(snail1, snail2);
    
  • Custom User Avatar

    I marked this as spoiler for you; please remember to mark code like that in the future ;)

  • Default User Avatar

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

  • Custom User Avatar

    Sorry can someone please explain why (array.pop() || []).reverse()) is used? specifically why is there the '|| []'?

    thanks so much

  • Custom User Avatar

    I am confused about this as well

  • Default User Avatar

    Mutating incoming "array" is considered a bad practice.

  • Custom User Avatar

    Oh god, that is infinitely easier to read than my code i love it. Genius. Good work

  • Custom User Avatar

    Basically, this one has it all and I've never said that before. It's waaay better than mine. The only thing: if line 2 was "var result = [];" you wouldn't need the ternary on line 5, you'd just concat every time.

  • Default User Avatar

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

  • Default User Avatar
  • Custom User Avatar

    Man... this is beautiful. Sooo much cleaner and straightforward than my approach. Nice work!

  • Loading more items...