Last active
August 29, 2015 14:15
-
-
Save dirkdunn/ab89098135d3b55b5502 to your computer and use it in GitHub Desktop.
BFX Helper Functions
This file contains 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
/* | |
This is an open Javascript library for the Borderfree BFX team. Included in this file will be | |
helper functions that can be incorperated into BFX projects. | |
Please leave comments above your code for readability. | |
*/ | |
// str.nthIndexOf(str,int) string method that grabs the substring at nth index. | |
String.prototype.nthIndexOf = function(sub,index){ | |
if(typeof sub === 'string' && typeof index === 'number'){ | |
var count = 0; | |
for(var i=0; i < this.length;i++){ | |
if(this[i] === sub){ | |
if(count === (index - 1)){ | |
return i; | |
} | |
count++; | |
} | |
} | |
}else{ | |
console.error("Wrong datatype for parameters."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment