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.

20 lines
448 B

4 years ago
  1. 'use strict';
  2. module.exports = function intersectByKeys(values) {
  3. var _this = this;
  4. var intersectKeys = Object.keys(values);
  5. if (values instanceof this.constructor) {
  6. intersectKeys = Object.keys(values.all());
  7. }
  8. var collection = {};
  9. Object.keys(this.items).forEach(function (key) {
  10. if (intersectKeys.indexOf(key) !== -1) {
  11. collection[key] = _this.items[key];
  12. }
  13. });
  14. return new this.constructor(collection);
  15. };