Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for First Word by s0me1
import assert from "assert";
function firstWord(text: string): string {
const separators = /[\ \,\.]/;
const words = text.split(separators).filter(w => w !== '');
return words[0];
}
console.log('Example:')
console.log(firstWord("Hello world"))
// These "asserts" using for self-checking and not for auto-testing
assert.equal(firstWord("Hello world"), "Hello")
assert.equal(firstWord(" a word "), "a")
assert.equal(firstWord("don't touch it"), "don't")
assert.equal(firstWord("greetings, friends"), "greetings")
assert.equal(firstWord("... and so on ..."), "and")
assert.equal(firstWord("hi"), "hi")
console.log("Coding complete? Click 'Check' to earn cool rewards!");
May 8, 2020