How to use the times function from ramda

Find comprehensive JavaScript ramda.times code examples handpicked from public code repositorys.

36
37
38
39
40
41
42
43
44
45
la(SUPPORTED_LAYOUTS[window.layout], 'layout not supported', window.layout)
var layoutParams = SUPPORTED_LAYOUTS[window.layout]
var {splitFlag, nextPaneFlag} = layoutParams;

// Create panes
var paneCommands = R.times((paneCommand) => {
  return `split-window ${splitFlag} -c "${config.root}"`
}, window.panes.length - 1)
paneCommands = R.intersperse(`select-pane ${nextPaneFlag}`, paneCommands)
windowCommands.push(paneCommands)
fork icon1
star icon3
watch icon0

34
35
36
37
38
39
40
41
42
static indexToKey(index: number): string {
    // map a numerical index to zero-padded string to guarantee order in case keys are sorted
    const unpaddedKey = index.toString()
    const digits = Math.ceil(Math.log10(Number.MAX_SAFE_INTEGER)) | 0

    const chars = times(() => '0', digits - unpaddedKey.length)

    return chars.join('') + unpaddedKey
}
fork icon0
star icon2
watch icon0

310
311
312
313
314
315
316
317
318
      }))
      .filter((up) => up.shipperId && up.vesselCode);
  })
  .flat();

const upIterationMap = times(
  (iteration) => iteration,
  Math.ceil(allUnpaids.length / iterationLimit),
);
fork icon0
star icon0
watch icon1

+ 11 other calls in file

9
10
11
12
13
14
15
16
17
18
var items = ['sunset','sunrise', 'flower', 'sky', 'boat', 'tree', 'road', 'twilight',
             'sunset','sunrise', 'flower', 'sky', 'boat', 'tree', 'road', 'twilight'];              
var randomItem = "";

// create list of random card objects from `items` list 
R.times(i=>{
    randomItem = _.random(0, items.length-1)
    cards.push({
        "id":            i,
        "open":          false,            
fork icon0
star icon0
watch icon1

37
38
39
40
41
42
43
44
45
46

let {stacks, moves} = data;

moves.forEach(m => {
    const {num, from, to} = m;
    R.times(x => {
        const v = stacks[from - 1].pop();
        stacks[to - 1].push(v);
    }, num);
    
fork icon0
star icon0
watch icon0

+ 3 other calls in file

4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
 * @param {Function} fn The function to invoke. Passed one argument, the current value of `n`.
 * @param {Number} n A value between `0` and `n - 1`. Increments after each function call.
 * @return {Array} An array containing the return values of all calls to `fn`.
 * @example
 *
 *      R.times(R.identity, 5); //=> [0, 1, 2, 3, 4]
 */
var times = _curry2(function times(fn, n) {
    var len = Number(n);
    var idx = 0;
fork icon0
star icon0
watch icon0

+ 17 other calls in file

104
105
106
107
108
109
110
111
112
113
114
// Return a random integer from x to y (inclusive)
const getRandomInt = (x, y) => (
  Math.floor(Math.random() * (y - x + 1) + x)
)


const makeGene = () => R.times(
  () => getRandomInt(0, 1),
  R.compose(R.length, R.head, Object.values)(geneMap)
)

fork icon0
star icon0
watch icon0

+ 8 other calls in file

76
77
78
79
80
81
82
83
84
85
86
87
  l[0][1] = 0;
  return l;
};


const getBoardSize = (l) => [l[1][0] - l[0][0] + 1, l[1][1] - l[0][1] + 1];
const makeBoard = (size) => R.times((_) => R.repeat('.', size[1]), size[0]);


const lines = R.compose(
    (ls) => ls.flat(),
    R.map(R.compose(
fork icon0
star icon0
watch icon0

12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
* @category List
* @sig a -> n -> [a]
* @param {*} value The value to repeat.
* @param {Number} n The desired size of the output list.
* @return {Array} A new array containing `n` `value`s.
* @see R.times
* @example
*
*      R.repeat('hi', 5); //=> ['hi', 'hi', 'hi', 'hi', 'hi']
*
fork icon0
star icon0
watch icon2

+ 19 other calls in file

25
26
27
28
29
30
31
32
33
34
    .splitEvery(4, line)
    .map(line => line.replace(/\[|\]/g, '').trim())
)

// We'll create a stack for each... stack.
const workingStacks = R.times(() => [], stacks[0].length)

// The stacks are listed top-down, but it would be simpler
// to process them bottom-up so we can create stacks in the
// data-structure sense.
fork icon0
star icon0
watch icon0

21
22
23
24
25
26
27
28
29
30
31
  return [...restTop, ...pickup, ...restBottom, value]
}


const crabGame = (moves) => {
  let cups = INITIAL_CUPS
  R.times(() => {
    cups = move(cups)
  }, moves)
  const [bottom, [one, ...top]] = R.splitWhen(R.equals(1), cups)
  return R.join("", [...top, ...bottom])
fork icon0
star icon0
watch icon0

35
36
37
38
39
40
41
42
43
44
    } else {
        return value * arg;
    }
}

R.times(n => {
    U.log(' -> iteration',n);

    monkeys.forEach(m => {
        m.items.forEach(i => {
fork icon0
star icon0
watch icon0

Other functions in ramda

Sorted by popularity

function icon

ramda.clone is the most popular function in ramda (30311 examples)