Ad
  • Custom User Avatar

    Because you have the initalization of your arr variable inside your loop so it continues to get reset.:)

  • Custom User Avatar

    According to the kata ranking system here is a description of 8 kyu: Imgur
    Seems to fit "Basic variable assignment" and "Basic math operations"

  • Custom User Avatar

    You should respect Kyu rang 8.

  • Custom User Avatar

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

  • Custom User Avatar

    Test cases check if your method return proper value, so you should add proper keyword :)

  • Default User Avatar

    I think where you're going wrong is that your for loop caps i by n.length rather than the value of n.

    Also your short-if should probably have a false condition with :

  • Default User Avatar
    • last[last.length-1] returns undefined because last is the name of the function, not of an argument.

    • list may be the unique argument if there's only one OR the 1st arg. if there're more than one.

      So, before returning "last of list" you should know if there's only 1 arg. or not.

  • Default User Avatar
    • typeof list return "object" if list is an array; you may use list instanceof Array instead;
    • your test typeof list=="array"||"string" returns "string" so it's always true and arguments[arguments.length-1] is never returned

    btw you test typeof list to choice what you return but beware that list is only the name of 1st argument (if there're more than one) and that this 1st argument may be a string or an array too.

    eg:

    last([1,2,3],["a","b","c"],[true,false])  // -> should return [true,false], because this is the **last** argument;
    last("red","blue","yellow")    // -> should return "yellow"
    

    keep on little padawan

  • Default User Avatar

    Your solution is a bit too complicated, in fact you may access to last argument simply with :
    arguments[arguments.length-1] as you do with your list.