Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

repeat string n times javascript

"a".repeat(10)
Comment

repeat call n times in js

// repeat call n times with identical parameters
// call is an async function
export const repeatCall = (call, {
  repeat = 1,
  params = [] // params is an array containing the parameters to `call` in the expected sequence 
}) => {

  const calls = [];

  for (let i = 0; i < repeat; i++) {
    calls.push(call(...params));
  }
  return calls;
}

// repeat call n times with unique parameters for each call
export const repeatUniqueCall = (call, {
  params = [] // params should be an array of arrays where each nested array with index i represents the params for call i
}) => {

  const calls = [];

  for (let i = 0; i < params.length; i++) {
    calls.push(call(...params[i]));
  }
  return calls;
}

// usage below
const myAsyncFunction = async (param1, param2) => {
  return await doSomething(param1, param2);
};

Promise.all(
  repeatCall(
    myAsyncFunction,
    {
      repeat: 3,
      params: ['value1', 'value2'],
    }
  ))
  .then((responses) => {
    // do something with responses
  })
Comment

PREVIOUS NEXT
Code Example
Javascript :: split array in to equal parts and make 2 array javascript 
Javascript :: normal function vs arrow function in javascript 
Javascript :: react import coreui icons 
Javascript :: ValueError: dictionary update sequence element #0 has length 1; 2 is required 
Javascript :: get difference of minutes between two time based on am, pm 
Javascript :: js email validation 
Javascript :: instagram unfollow console code 
Javascript :: stop jboss from cli 
Javascript :: react testing library increase debug length 
Javascript :: how to give default value in jquery 
Javascript :: snackbar in react 
Javascript :: invert linked list js 
Javascript :: nodejs convert buffer to uint8array 
Javascript :: list of states js 
Javascript :: for loop with if statement 
Javascript :: how to log bodyparser error 
Javascript :: return array javascript 
Javascript :: How to find out what character key is pressed?#key#keyCode#code 
Javascript :: identity-obj-proxy not working 
Javascript :: map every second character jaavascript 
Javascript :: python run javascript 
Javascript :: three ways of writing a function in javascript 
Javascript :: outputstream to image js example 
Javascript :: how to give data from react native to webview 
Javascript :: js retry function if error 
Javascript :: react hotjar 
Javascript :: js set css 
Javascript :: jquery check if input is empty on keyup 
Javascript :: build json object 
Javascript :: window.focus and window.blur jquery 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =