Created
November 16, 2017 21:15
-
-
Save fdjones/11a49532a4635b5f069bd51f10a6e998 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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