combinatorics/variations-repetition

Finds all the variations with repetition of given array.

Variations with repetition is the number of ways to sample k elements from a set of elements (which may be repeated).
Source:
Parameters:
Name Type Description
arr Array Set of items.
k Number Size of each combination.
Returns:
Type:
Array
Returns all combinations.
Example
var variations = require('path-to-algorithms/src/combinatorics/' +
'variations-repetition').variationsWithRepetion;
var result = variations(['apple', 'orange', 'pear'], 2);

// [['apple', 'apple'],
//  ['apple', 'orange'],
//  ['apple', 'pear'],
//  ['orange', 'apple'],
//  ['orange', 'orange'],
//  ['orange', 'pear'],
//  ['pear', 'apple'],
//  ['pear', 'orange'],
//  ['pear', 'pear']]
console.log(result);