Skip to content

Instantly share code, notes, and snippets.

@aMarCruz
Last active December 26, 2018 02:01
Show Gist options
  • Select an option

  • Save aMarCruz/7892c05992d9ba559c99 to your computer and use it in GitHub Desktop.

Select an option

Save aMarCruz/7892c05992d9ba559c99 to your computer and use it in GitHub Desktop.

Revisions

  1. aMarCruz revised this gist Jun 29, 2016. 1 changed file with 5 additions and 7 deletions.
    12 changes: 5 additions & 7 deletions starts_ends_with.js
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,14 @@
    ;(function () {

    var sp = String.prototype;
    ;(function (sp) {

    if (!sp.startsWith)
    sp.startsWith = function (str) {
    return !this.lastIndexOf(str, 0)
    return !!(str && this) && !this.lastIndexOf(str, 0)
    }

    if (!sp.endsWith)
    sp.endsWith = function (str) {
    var offset = this.length - str.length;
    return offset >= 0 && src.slice(offset) === str;
    var offset = str && this ? this.length - str.length : -1
    return offset >= 0 && this.lastIndexOf(str, offset) === offset
    }

    })();
    })(String.prototype);
  2. aMarCruz revised this gist Jul 30, 2015. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions starts_ends_with.js
    Original file line number Diff line number Diff line change
    @@ -3,12 +3,14 @@
    var sp = String.prototype;

    if (!sp.startsWith)
    sp.startsWith = function (str) { return !this.lastIndexOf(str, 0) }
    sp.startsWith = function (str) {
    return !this.lastIndexOf(str, 0)
    }

    if (!sp.endsWith)
    sp.endsWith = function (str) {
    var offset = this.length - str.length;
    return offset >= 0 && this.indexOf(str, offset) == offset;
    return offset >= 0 && src.slice(offset) === str;
    }

    })();
  3. aMarCruz revised this gist Jul 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion starts_ends_with.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    var sp = String.prototype;

    if (!sp.startsWith)
    sp.startsWith = function (str) { !this.lastIndexOf(str, 0) }
    sp.startsWith = function (str) { return !this.lastIndexOf(str, 0) }

    if (!sp.endsWith)
    sp.endsWith = function (str) {
  4. aMarCruz renamed this gist Jul 30, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. aMarCruz created this gist Jul 16, 2015.
    14 changes: 14 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    ;(function () {

    var sp = String.prototype;

    if (!sp.startsWith)
    sp.startsWith = function (str) { !this.lastIndexOf(str, 0) }

    if (!sp.endsWith)
    sp.endsWith = function (str) {
    var offset = this.length - str.length;
    return offset >= 0 && this.indexOf(str, offset) == offset;
    }

    })();