Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Words Order by pokosasa
import assert from "assert";
function wordsOrder(text: string, words: string[]): boolean {
if(new Set(words).size != words.length)return false;
text.split(" ").map(word => word === words[0] ? words.shift() : "");
return !words.length;
}
console.log('Example:');
console.log(wordsOrder('hi world im here', ['world', 'here']));
// These "asserts" are used for self-checking
assert.equal(wordsOrder('hi world im here', ['world', 'here']), true);
assert.equal(wordsOrder('hi world im here', ['here', 'world']), false);
assert.equal(wordsOrder('hi world im here', ['world']), true);
assert.equal(wordsOrder('hi world im here',
['world', 'here', 'hi']), false);
assert.equal(wordsOrder('hi world im here',
['world', 'im', 'here']), true);
assert.equal(wordsOrder('hi world im here',
['world', 'hi', 'here']), false);
assert.equal(wordsOrder('hi world im here', ['world', 'world']), false);
assert.equal(wordsOrder('hi world im here',
['country', 'world']), false);
assert.equal(wordsOrder('hi world im here', ['wo', 'rld']), false);
assert.equal(wordsOrder('', ['world', 'here']), false);
assert.equal(wordsOrder('hi world world im here',
['world', 'world']), false);
console.log("Coding complete? Click 'Check' to earn cool rewards!");
March 15, 2021