Ad
  • 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

    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);