Forked from anonymous/Pattern Maker (1.6 Extra Problems).js
Created
July 31, 2016 18:38
-
-
Save sethschori/fcd6fa1a2ead2628e2171d4b0eeec227 to your computer and use it in GitHub Desktop.
https://repl.it/CZ1m/33 created by sethopia
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
/* | |
Pattern Master | |
create a function patternMaker() that takes two arguments: an integer n and a piece of data of any type. patternMaker() should return an array of the second argument, repeated n times | |
ex) | |
patternMaker(5, 'Boo') --> ['Boo', 'Boo', 'Boo', 'Boo', 'Boo'] | |
patternMaker(3, ['cat', 'dog']) --> [['cat', 'dog'], ['cat', 'dog'], ['cat', 'dog']] | |
*/ | |
function patternMaker(n, item) { | |
var returnArr = []; | |
for (var i = 0; i < n; i++) { | |
returnArr.push(item); | |
} | |
return returnArr; | |
} | |
console.log(patternMaker(5, 'Boo')); | |
// ['Boo', 'Boo', 'Boo', 'Boo', 'Boo']) | |
console.log(patternMaker(3, ['cat', 'dog'])); | |
// [['cat', 'dog'], ['cat', 'dog'], ['cat', 'dog']]) |
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
Native Browser JavaScript | |
>>> [ 'Boo', 'Boo', 'Boo', 'Boo', 'Boo' ] | |
[ [ 'cat', 'dog' ], [ 'cat', 'dog' ], [ 'cat', 'dog' ] ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment