mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2024-12-27 06:40:42 -05:00
20 lines
543 B
JavaScript
20 lines
543 B
JavaScript
function replicate(multiple, number) {
|
|
if (multiple <= 0) return [];
|
|
|
|
// let arr = [];
|
|
|
|
// original and too long
|
|
// if (multiple >= 1) {
|
|
// arr.push(number);
|
|
// } else {
|
|
// arr.push(replicate(multiple - 1), number);
|
|
// }
|
|
// const concated = arr.concat(replicate(multiple - 1, number));
|
|
// return concated;
|
|
return [number].concat(replicate(multiple - 1, number));
|
|
}
|
|
|
|
console.log(replicate(3, 5)); // [5, 5, 5]
|
|
console.log(replicate(1, 69)); // [69]
|
|
console.log(replicate(-2, 6)); // []
|
|
console.log(replicate(60, 30));
|