Skip to content

Instantly share code, notes, and snippets.

@fdjones
Created November 16, 2017 21:13
Show Gist options
  • Save fdjones/370fcb572d8c733efd748e95c6a653ce to your computer and use it in GitHub Desktop.
Save fdjones/370fcb572d8c733efd748e95c6a653ce to your computer and use it in GitHub Desktop.
function foo() {
return {
input: this.input,
delimiter: this.delimier,
push: function(newString) {
this.input = this.input ? this.input + this.delimiter + newString : newString;
},
pop: function() {
const LAST_INDEX = this.input.lastIndexOf(this.delimiter);
this.input = (LAST_INDEX !== -1) ? this.input.substring(0, LAST_INDEX) : '';
},
concat: function(newString) {
return this.input ? this.input + this.delimiter + newString : newString;
},
indexesOf: function(n) {
let indexesString = '';
for(let i = 0; i < this.input.length; i++) {
if(n === this.input[i]) {
indexesString += i + ', ';
}
}
let lastIndexofComma = indexesString.lastIndexOf(',');
return indexesString.substring(0, lastIndexofComma);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment