Ad
  • Custom User Avatar

    I really enjoyed this one! Although my own solution ultimately didn't work and I resorted to comparing existing algorithms and implementations, I learned a lot.

    I definitely agree with other commenters - these kinds of problems often seems to be about finding the right algorithm.

  • Custom User Avatar

    That's a cool solution!

    I assume it has been generated somehow. How does it work? :D

  • Custom User Avatar

    Thanks for the quick reply! :)

  • Custom User Avatar

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

  • Custom User Avatar

    I might have found a solution, see my issue above!

  • Custom User Avatar

    This could be related to @MikeHathaway's comment below, but my case is a little bit different. I don't get the "u r using restricted stuff" error message but i do have 500/501 tests passing.

    After looking closer at the failing test, I realised that the issue is with the tests themselves:

    This is the second sample test

    Test.assertEquals(isPrime(-7), true);
    

    The third basic test for the attempt-suite fails as well.

    Test.assertEquals(isPrime(-6), true);
    

    Negative numbers aren't prime. The expected results of these tests should therefore be false.

    In addition to that, the instructions has an invalid example with a negative number as well. It's a good idea to test with negative numbers - but only if the test cases have correct assertions.

  • Custom User Avatar

    Could you show your code for reference? :)

  • Custom User Avatar

    Interesting approach! Not the shortest but still quite clean :)

  • Custom User Avatar

    This repetition is a good example of when it's recommended to use an abstraction to separate the logic (your ifs and elses) from the data of a similar format (the roman numerals and the values they represent).

    Since the data is in a clear key: value format, an object {} would be great.

    Good luck, and happy coding! :)

  • Custom User Avatar

    Only thanks to the random tests, I found an edge case related to an "off by one" error in my solution (See range(m, n) which initially didn´t use an inclusive upper bound). I initially passed with an incomplete solution but once I tested again it didn't pass.

    How about adding an additional basic test case similar to the following?

    Test.assertSimilar(listSquared(1, 42), [[1, 1], [42, 2500]], 'It should handle cases where the upper bound itself is a solution.')
    
  • Custom User Avatar

    Could you give some example code? :)

    From https://mdn.io/call:
    Function.prototype.call() returns

    "The result of calling the function with the specified this value and arguments."

    You can basically use array methods on strings and vice versa.

    For example, an array can be "split" into pieces just like a regular string:

    > String.prototype.split.call(['a', 'b', 'c'], '')
    ["a", ",", "b", ",", "c"]
    

    This is basically the same as running:

    ['a', 'b', 'c'].split('')
    

    Where the array is treated as the this value:

    ['a', 'b', 'c']
    

    And this is the argument:

    ''