You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
838 B
34 lines
838 B
4 years ago
|
'use strict';
|
||
|
|
||
|
module.exports = function crossJoin() {
|
||
|
function join(collection, constructor, args) {
|
||
|
var current = args[0];
|
||
|
|
||
|
if (current instanceof constructor) {
|
||
|
current = current.all();
|
||
|
}
|
||
|
|
||
|
var rest = args.slice(1);
|
||
|
var last = !rest.length;
|
||
|
var result = [];
|
||
|
|
||
|
for (var i = 0; i < current.length; i += 1) {
|
||
|
var collectionCopy = collection.slice();
|
||
|
collectionCopy.push(current[i]);
|
||
|
|
||
|
if (last) {
|
||
|
result.push(collectionCopy);
|
||
|
} else {
|
||
|
result = result.concat(join(collectionCopy, constructor, rest));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
for (var _len = arguments.length, values = Array(_len), _key = 0; _key < _len; _key++) {
|
||
|
values[_key] = arguments[_key];
|
||
|
}
|
||
|
|
||
|
return new this.constructor(join([], this.constructor, [].concat([this.items], values)));
|
||
|
};
|