repeat x times js

Solutions on MaxInterview for repeat x times js by the best coders in the world

showing results for - "repeat x times js"
Romina
19 Feb 2020
1"a".repeat(10)
Stacey
02 Sep 2018
1The code below is written using ES6 syntaxes but could just as easily be written in ES5 or even less. ES6 is not a requirement to create a "mechanism to loop x times"
2
3If you don't need the iterator in the callback, this is the most simple implementation
4
5const times = x => f => {
6  if (x > 0) {
7    f()
8    times (x - 1) (f)
9  }
10}
11
12// use it
13times (3) (() => console.log('hi'))
14
15// or define intermediate functions for reuse
16let twice = times (2)
17
18// twice the power !
19twice (() => console.log('double vision'))
queries leading to this page
repeat x time jsjavascript repeat string n timesrepeat function for int times jsrepeat a single string multiple times jsjs 2brepeat string n timesrepeat something a certain amount of times javascriptjs string repeat x timerepeat code x times javascriptrepeat set amount of times jsjavascript repeat text n timesrepeat 10 times javascriptjavasceript repeat 3 timesrepeat a string n times javascriptrepeat word 1000 times jshow to repeat a character n times in javascriptjs repeat html n timesnode js repeat x timesrepeat a string n times jsjavascript repeat a function n timesrepeat n times javascriptes6 repeat string n timesrepeat 10 times for loop javascriptrepeat string number of times jsjs repeat n timesjavascript repeat string multiple timesjs repeat x timesjavascript repeat function n timesjavascript function to repeat a text a number of timesjs repeat int amount of timesrepeat n times javascript for injs repeat a string n timesrepeat function javascript 8 timesrepeat code 2 times javascriptrepeat a function for times jsrepeat x times javascriptjs repeat something 10 timesrepeat loop x time javascriptrepeat x times jsrepeat a word 1000 times with loop in javascriptrepeat function n times in x times javascriptrepeat something x times jsjs repeat letter timesjs how to repeat a number 100 timesrepeat something 3 times jsjs repeat string n timesjs repeat function n timesjavascript repeat 5 timesrepeat string x times javascriptrepeat a string certain times jsjavascript repeat a character n timesrepeat 5 times jshow to repeat a string n times in javascriptnode repeat string n timeshow to repeat an amount of times javascriptrepeat n times a string for a new string javascriptrepeat function a number of times javascriptjavascript repeat timesrepeat string n times javascriptjavascript repeat function every x secondsrepeat a string n times in jsjavascript repeat function 3 timesjavascript repeat n timesjevascript repeat 4 timesjavascript repeat character n timesjs string repeat n timesrepeat a string n times javascript with a for looprepeat a function amount of times jsjavascript repeat x timesjs repeat html x timesjavascript repeat string x timesrepeat the 2 entries 50 times in jsjs repeat character n timeshow to repeat in javascript for n timesrepeat x times js