Ad
  • Custom User Avatar

    You're right. I corrected this mistake and all JS tests passed. Thank you for your help.

  • Custom User Avatar

    You're using the built-in function in line 2 incorrectly.

  • Custom User Avatar

    Thank you for your answer. I guess there is something wrong with my JS solution then.

  • Custom User Avatar

    Both seem fine to me. I just passed on both with very similar solutions.

  • Custom User Avatar

    All random test failed for solution in JavaScript. Submitted the same solution in Ruby, all tests passed. Is there a problem with JavaScript random tests?

  • Custom User Avatar

    It would probably be better to do a null check before a length check (arr == null || arr.length == 0), if the order is reversed, null check becomes redundant.

  • Custom User Avatar

    I guess that checking for a for-each-loop use in a solution means checking for an iterator method call. So maybe you can extend ArrayList (or other implementation to be used as a fn parameter) and override iterator method. Like that:

    class MyList<T> extends ArrayList<T> {
            @Override
            public Iterator<T> iterator() {
                throw new UnsupportedOperationException();
    //            return super.iterator();
            }
        }
    

    Maybe do the same for some other methods (get for example).