Js vs. C# queryable strings
This example should split the sentence into an array of words and select those whose first leter is a vowel
by austinpray
HTML
<h1>Input</h1>
<p id="input">loading</p>
<h1>Output</h1>
<pre id="result">
loading
</pre>
SCSS
$color: #BADA55;
body {
background: lighten($color, 35%);
color: darken(complement($color), 35%);
font-family:"Helvetica", sans-serif;
font-weight: 300;
}
JavaScript
var strings = [
"A penny saved is a penny earned.",
"The early bird catches the worm",
"The pen is mightier than the sword"];
function vowelFinder(single) {
var vowels = ["a", "e", "i", "o", "u"];
return single.split(' ').filter(function (el) {
return vowels.some(function (vowel) {
return el[0].toLowerCase() === vowel;
});
});
}
//takes an array of strings, s
//returns the words whose first letter starts with a vowel
function earlyBird(s) {
return [].concat.apply([], s.map(vowelFinder));
}
var print = new earlyBird(strings);
console.log(print);
document.getElementById("input").innerHTML = strings;
document.getElementById("result").innerHTML = print;