intersectByKeys.js 446 B

12345678910111213141516171819
  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. };