code: function earliestSubstring(needles, haystack) {
      let minPosition = haystack.length;
      let position, minNeedle = undefined;
      needles.forEach((needle) => {
          position = haystack.indexOf(needle);
          if (position !== -1) {
              minPosition = Math.min(minPosition, position);
              if (minPosition === position) {
                  minNeedle = needle;
              }
          }
      });
      return minNeedle;
  }
docs: Given an array of substrings to search for (needles), return the substring
  that occurs at the earliest location inside the haystack. If no needs
  are present in the haystack, return undefined.
  
  @param {string[]} needles Strings to search for
  @param {string} haystack String that should contains a needles
  @return {string|undefined} The needles that occurs earlier in the haystack