Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
ES6, regex solution in Clear category for [old] First Word by matejm
'use strict';
const assert = require('assert');
const firstWord = (string) => string.match(/[a-zA-Z']+/)[0];
if (!global.is_checking) {
assert.strictEqual(
firstWord('Hello world'),
'Hello',
);
assert.strictEqual(
firstWord(' a word '),
'a',
);
assert.strictEqual(
firstWord('don\'t touch it'),
'don\'t',
);
assert.strictEqual(
firstWord('greetings, friends'),
'greetings',
);
assert.strictEqual(
firstWord('... and so on ...'),
'and',
);
assert.strictEqual(
firstWord('hi'),
'hi',
);
}
Dec. 16, 2018