← Back to challenges

Repeat the Same Item Multiple Times

JavaScriptHardarraysloops

Instructions

Create a function that takes two arguments (item, times). The first argument (item) is the item that needs repeating while the second argument (times) is the number of times the item is to be repeated. Return the result in an array.

Examples

repeat("innokodakademija", 3) ➞ ["innokodakademija", "innokodakademija", "innokodakademija"]

repeat(13, 5) ➞ [13, 13, 13, 13, 13]

repeat("7", 2) ➞ ["7", "7"]

repeat(0, 0) ➞ []

Notes

  • item can be either a string or a number.
  • times will always be a number.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Is the Object Empty?