Ad
  • Custom User Avatar

    And what about this?

    last({}, { length: 'foo' }); //'foo' - 1? WTF?

  • Custom User Avatar

    A bit late, but... Could you please reformat it with starting and ending triple backticks, then tell us the relevant error message?

    Wasn't anyway using Math.max() for maxLength or directly return either true/false or a better way of handling things?

    P.S.: cool Latin nick.

  • Default User Avatar

    Because the number of solutions already registered (>1300) I think now kata can not be changed.

  • Custom User Avatar

    As already mentioned, there're some corner cases, that don't fit.

    Test.assertEquals(last(), undefined); //-- undefined
    Test.assertEquals(last(1, [2, 3]), [2, 3]);//-- last item is array

  • Default User Avatar

    I think if there are multiple arguments and the last one is an array, the return value could be a little bit confusing. Of course a special situation but who knows :)

  • Default User Avatar

    Your functions are changing the values array. It wasn't originally [11, 12] - your minimumSum function changed it.

    Try logging values before and after calling your functions to see that it's being changed within your function:

    var values = [1,2,3,4,5];
    console.log(values);
    console.log(minimumSum(values, 2));   // it should log 3 (1+2)
    console.log(values);
    console.log(maximumSum(values, 2));   // it should log 9 (4+5)
    console.log(values);
    

    Javascript passes arrays and objects by reference, so if your code changes the array, it can have unintended side effects. Always try to avoid changing objects and arrays that were passed as arguments. If you need to modify them, make a copy first and modify that.

  • Default User Avatar

    Hi,

    If you try to run an test of your own with the following values, what do you get as an answer?

    var values = [12, 11, 10, 9, 8];
    maximumSum(values, 3);
    
  • Custom User Avatar

    Got an error : "maximumSum with n=3 not working" while submitting. While inspecting console.log gives :

    1. values : [ 11, 12 ]
    2. n : 3
    3. returns : 23

    What's wrong???

  • Custom User Avatar

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