Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
BM - SLR - Slice, TernOp, Includes, indexOf, lastIndexOf solution in Clear category for Between Markers by Taylor_Page
import assert from "assert";
function betweenMarkers(text: string, begin: string, end: string): string {
return text.slice(
// Checks for and sets start index from "begin"
text.includes(begin) ? text.indexOf(begin) + begin.length : 0,
// Checks for and sets final index from "end"
text.includes(end) ? text.lastIndexOf(end) : text.length
)
}
console.log('Example:')
console.log(betweenMarkers('What is >apple<', '>', '<'), 'apple')
assert.equal(betweenMarkers('What is >apple<', '>', '<'), 'apple')
assert.equal(betweenMarkers("My new site",
"", ""), 'My new site')
assert.equal(betweenMarkers('No[/b] hi', '[b]', '[/b]'), 'No')
assert.equal(betweenMarkers('No [b]hi', '[b]', '[/b]'), 'hi')
assert.equal(betweenMarkers('No hi', '[b]', '[/b]'), 'No hi')
assert.equal(betweenMarkers('No ', '>', '<'), '')
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
June 3, 2020