This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Duck Punching in JavaScript | |
const sentence = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?'; | |
const legacyIndexOf = String.prototype.indexOf; | |
// Extending the indexOf functionality to return the last occurence of the searchValue | |
String.prototype.indexOf = function (searchValue, fromIndex, getLastIndexFlag = false) { | |
if (!getLastIndexFlag) { | |
return legacyIndexOf.call(this, searchValue, fromIndex); |