Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Words Order by Elena_Korljukova
import assert from "assert";
function wordsOrder(text: string, words: string[]): boolean {
let t = text.split(' ');
if (words.length != new Set(words).size || t.length < words.length) return false;
for (let i of words) {
if (t.indexOf(i) == -1) return false;
t = t.slice(t.indexOf(i) + 1);
}
return true;
}
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!");
July 26, 2020