SFRA Server-side Javascript - Source: app_storefront_base/cartridge/scripts/util/array.js menu

SFRA / Server-side JS / Source: app_storefront_base/cartridge/scripts/util/array.js

  1. 'use strict';
  2. /**
  3. * Returns a value of the first element in the array that satisfies the provided testing function.
  4. * Otherwise undefined is returned.
  5. * @param {Array} array - Array of elements to find the match in.
  6. * @param {Array} matcher - function that returns true if match is found
  7. * @return {Object|undefined} element that matches provided testing function or undefined.
  8. */
  9. function find(array, matcher) {
  10. for (var i = 0, l = array.length; i < l; i++) {
  11. if (matcher(array[i], i)) {
  12. return array[i];
  13. }
  14. }
  15. return undefined;
  16. }
  17. module.exports = {
  18. find: find
  19. };