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.

24 lines
518 B

4 years ago
'use strict';
module.exports = function replace(items) {
if (!items) {
return this;
}
if (Array.isArray(items)) {
const replaced = this.items.map((value, index) => items[index] || value);
return new this.constructor(replaced);
}
if (items.constructor.name === 'Collection') {
const replaced = Object.assign({}, this.items, items.all());
return new this.constructor(replaced);
}
const replaced = Object.assign({}, this.items, items);
return new this.constructor(replaced);
};