Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
slice solution in Clear category for [old] Middle Characters by Sim0000
"use strict";
function middle(text) {
let n = (text.length >> 1) + 1;
return text.slice(-n, n);
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(middle('example'))
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(middle('example'), 'm')
assert.equal(middle('test'), 'es')
assert.equal(middle('very-very long sentence'), 'o')
assert.equal(middle('I'), 'I')
assert.equal(middle('no'), 'no')
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
May 15, 2018
Comments: