Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Striped Words by kurosawa4434
"use strict";
function stripedWords(text){
const vowels = '[AEIOUY]',
consonants = '[BCDFGHJKLMNPQRSTVWXZ]',
re_v = new RegExp(vowels),
re_c = new RegExp(consonants),
re_v2 = new RegExp(vowels+'{2,}'),
re_c2 = new RegExp(consonants+'{2,}'),
re_num = new RegExp(/\d/),
split_text = text.toUpperCase().split(/[ .,]+/);
var result = 0;
split_text.forEach(t=>{
if (re_v.test(t)
&& ! re_v2.test(t)
&& re_c.test(t)
&& ! re_c2.test(t)
&& ! re_num.test(t)) {
result += 1;
}
});
return result;
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(stripedWords("My name is ..."), 3, "All words are striped");
assert.equal(stripedWords("Hello world"), 0, "No one");
assert.equal(stripedWords("A quantity of striped words."), 1, "Only of");
assert.equal(stripedWords("Dog,cat,mouse,bird.Human."), 3, "Dog, cat and human");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
March 16, 2017