Skip to content

Instantly share code, notes, and snippets.

@dirkdunn
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dirkdunn/ab89098135d3b55b5502 to your computer and use it in GitHub Desktop.
Save dirkdunn/ab89098135d3b55b5502 to your computer and use it in GitHub Desktop.
BFX Helper Functions
/*
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