a zip code crypto-currency system good for red ONLY

find-component-in.js 953B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var compactable = require('../compactable');
  2. function findComponentIn(shorthand, longhand) {
  3. var comparator = nameComparator(longhand);
  4. return findInDirectComponents(shorthand, comparator) || findInSubComponents(shorthand, comparator);
  5. }
  6. function nameComparator(to) {
  7. return function (property) {
  8. return to.name === property.name;
  9. };
  10. }
  11. function findInDirectComponents(shorthand, comparator) {
  12. return shorthand.components.filter(comparator)[0];
  13. }
  14. function findInSubComponents(shorthand, comparator) {
  15. var shorthandComponent;
  16. var longhandMatch;
  17. var i, l;
  18. if (!compactable[shorthand.name].shorthandComponents) {
  19. return;
  20. }
  21. for (i = 0, l = shorthand.components.length; i < l; i++) {
  22. shorthandComponent = shorthand.components[i];
  23. longhandMatch = findInDirectComponents(shorthandComponent, comparator);
  24. if (longhandMatch) {
  25. return longhandMatch;
  26. }
  27. }
  28. return;
  29. }
  30. module.exports = findComponentIn;