Simple repeat function implementation in JS

Testing: