Skip to content

Instantly share code, notes, and snippets.

@pgainda
Created May 8, 2013 15:18
Show Gist options
  • Save pgainda/5541170 to your computer and use it in GitHub Desktop.
Save pgainda/5541170 to your computer and use it in GitHub Desktop.
To make the subset of the string include the character at the start index, set i equal to start in the first loop parameter. To make the subset include the character at the end index, use the <= operator to compare i and end in the second loop parameter. Since characters are numbered by ones, increment i by one in the third loop parameter.
// Define substring here
function subString(input, start, end){
var i;
this.input = input;
this.start = start;
this.end = end;
for(i=start;i<=end;i++){
console.log(input[i]);
}
}
// Write test here:
// Call substring, passing "lorem ipsum dolor" to `input`, `6` to
// `start`, and `10` to `end`.
subString("lorem ipsum dolor",6,10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment