Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Words Order by vvikota
import assert from "assert";
function wordsOrder(text: string, words: string[]): boolean {
let index = -1
let result = true
for (let word of words) {
let currentIndex = text.split(' ').indexOf(word)
currentIndex > index ? index = currentIndex : result = false
}
return result
}
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 23, 2021
Comments: