Test case details

Preparation Code

<script>   var container = 'qwertyuiop';   var trues = ['', 'p', 'op', 'qwertyuiop'];   var falses = [' ', 'po', '1qwertyuiop'];     function test(endsWith) {     var i = 99999;     while (i--) {       trues.forEach(function(s) {         if (!endsWith.call(container, s)) {           throw new Error(s + ' FAILS!');         }       });       falses.forEach(function(s) {         if (endsWith.call(container, s)) {           throw new Error(s + ' FAILS!');         }       });     }   } </script>

Test cases

Test #1

test(function(s) {   return this.substring(this.length - s.length) === String(s); });

Test #2

test(function(s) {   var t = String(s);   var index = this.lastIndexOf(t)   return index >= 0 && index === this.length - t.length; });

Test #3

test(function(s) {   s = String(s);   var i = s.length;   var thisStartIndex = this.length - i;   while (i--) {     if (s.charAt(i) !== this.charAt(thisStartIndex + i)) {       return false;     }   }   return true; });