Ohm-Management - Projektarbeit B-ME
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.

pluck.js 703B

12345678910111213141516171819202122232425
  1. import { map } from './map';
  2. export function pluck(...properties) {
  3. const length = properties.length;
  4. if (length === 0) {
  5. throw new Error('list of properties cannot be empty.');
  6. }
  7. return (source) => map(plucker(properties, length))(source);
  8. }
  9. function plucker(props, length) {
  10. const mapper = (x) => {
  11. let currentProp = x;
  12. for (let i = 0; i < length; i++) {
  13. const p = currentProp[props[i]];
  14. if (typeof p !== 'undefined') {
  15. currentProp = p;
  16. }
  17. else {
  18. return undefined;
  19. }
  20. }
  21. return currentProp;
  22. };
  23. return mapper;
  24. }
  25. //# sourceMappingURL=pluck.js.map