Skip to content

Instantly share code, notes, and snippets.

@gdibble
Last active May 20, 2016 22:04
Show Gist options
  • Select an option

  • Save gdibble/73821f9eef2d74084a2c to your computer and use it in GitHub Desktop.

Select an option

Save gdibble/73821f9eef2d74084a2c to your computer and use it in GitHub Desktop.

Revisions

  1. gdibble revised this gist Oct 23, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions reIndexOf.js
    Original file line number Diff line number Diff line change
    @@ -7,9 +7,9 @@
    * @return {Numeric} -1 means not found
    */
    if (typeof Array.prototype.reIndexOf === 'undefined') {
    Array.prototype.reIndexOf = function (rx) {
    Array.prototype.reIndexOf = function (str) {
    for (var i in this) {
    if (this[i].toString().match(rx)) {
    if (str.toString().match(this[i])) {
    return i;
    }
    }
  2. gdibble created this gist Oct 23, 2015.
    18 changes: 18 additions & 0 deletions reIndexOf.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    /**
    * Regular Expresion IndexOf for Arrays
    * This little addition to the Array prototype will iterate over array
    * and return the index of the first element which matches the provided
    * regular expresion. Note: This will not match on objects.
    * @param {RegEx} rx The regular expression to test with. E.g. /-ba/gim
    * @return {Numeric} -1 means not found
    */
    if (typeof Array.prototype.reIndexOf === 'undefined') {
    Array.prototype.reIndexOf = function (rx) {
    for (var i in this) {
    if (this[i].toString().match(rx)) {
    return i;
    }
    }
    return -1;
    };
    }