Created
September 18, 2020 19:29
-
-
Save arnonate/6fb4a9caeb23cb7d582e0b2dee6a08b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myConcat(separator) { | |
var result = ""; // initialize list | |
var i; | |
// iterate through arguments | |
for (i = 1; i < arguments.length; i++) { | |
result += arguments[i] + separator; | |
} | |
return result; | |
} | |
// returns "red, orange, blue, " | |
myConcat(", ", "red", "orange", "blue"); | |
// returns "elephant; giraffe; lion; cheetah; " | |
myConcat("; ", "elephant", "giraffe", "lion", "cheetah"); | |
// returns "sage. basil. oregano. pepper. parsley. " | |
myConcat(". ", "sage", "basil", "oregano", "pepper", "parsley"); | |
// The rest parameter syntax allows us to represent | |
// an indefinite number of arguments as an array. | |
function multiply(multiplier, ...theArgs) { | |
return theArgs.map(x => multiplier * x); | |
} | |
var arr = multiply(2, 1, 2, 3); | |
console.log(arr); // [2, 4, 6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment