Created
November 16, 2017 21:13
-
-
Save fdjones/370fcb572d8c733efd748e95c6a653ce 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() { | |
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