Skip to content

Instantly share code, notes, and snippets.

@fdjones
Created November 16, 2017 21:15
Show Gist options
  • Save fdjones/11a49532a4635b5f069bd51f10a6e998 to your computer and use it in GitHub Desktop.
Save fdjones/11a49532a4635b5f069bd51f10a6e998 to your computer and use it in GitHub Desktop.
function foo(arg1, arg2) {
return {
input: arg1,
delimiter: arg2,
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