Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear&Readable solution in Clear category for [old] Between Markers by SaintDron
"use strict";
function betweenMarkers(text, begin, end) {
if (!begin && !end)
return '';
let beginIndex = (~text.indexOf(begin)) ? text.indexOf(begin) + begin.length : 0;
let endIndex = (~text.indexOf(end)) ? text.indexOf(end) : text.length;
if (beginIndex > endIndex)
return '';
return text.slice(beginIndex, endIndex);
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(betweenMarkers())
assert.equal(betweenMarkers('What is >apple<', '>', '<'), 'apples')
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!");
}
March 1, 2018
Comments: