function arglength() {
    return arguments.length;
}

assert(0, arglength());
assert(1, arglength('a'));
assert(2, arglength('a', 'b'));

function sum() {
    var result = 0;

    for (var i = 0; i < arguments.length; i++) {
        result += arguments[i];
    }

    return result;
}

assert(10, sum(1, 2, 3, 4));

function myConcat(separator) {
  var result = "";

  // iterate through non-separator arguments
  for (var i = 1; i < arguments.length; i++)
      result += arguments[i] + separator;
  
  return result;
}

// You can pass any number of arguments to this function, and it creates a list using each argument as an item in the list.

assert("red, orange, blue, ", myConcat(", ", "red", "orange", "blue"));

Last edited Oct 11, 2009 at 12:51 PM by sebastienros, version 1

Comments

No comments yet.