Repeat the Same Item Multiple Times

Published by Helen Yu in

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("edabit", 3) ➞ ["edabit", "edabit", "edabit"]

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

repeat("0", 0) ➞ []

Notes

  • item will be a string.
  • times will always be a number.
Watch a quick demo on how Edabit works.