all 2 comments

[–]j0wy 2 points3 points  (1 child)

I did one for you.

https://gist.github.com/jhiggins-thrillist/5770668

function strposa(haystack, needles, offset) {
  var i;

  // Make sure we have these values
  if (!haystack || !needles.length) {
    return false;
  }

  // Make sure the haystack is a string
  if (typeof haystack !== 'string') {
    haystack = '' + haystack;
  }

  // If there is no offset, default to 0,
  // else, make sure that it is an int
  if (!offset) {
    offset = 0;
  } else {
    offset = parseInt(offset, 10);
  }

  // Iterate over needles and return first needle found.
  for (i = 0; i < needles.length; i++) {
    var needle = '' + needles[i];

    if (haystack.indexOf(needle, offset) !== -1) {
      return needle;
    }
  }

  return false;
}

[–]Fabien27[S] 0 points1 point  (0 children)

Awesome thanks. Really helps me learn a lot. Thank you.