menu
announcement

Spectrum is now read-only. Learn more about the decision in our official announcement.

Deno

A secure TypeScript runtime built on V8

Channels
Team

[NEWBIE] await - how pervasive does it get / should it get?

June 12, 2020 at 1:47am

[NEWBIE] await - how pervasive does it get / should it get?

June 12, 2020 at 1:47am
const rex = /[aeiou]{1}/ig;
const res = await fetch(
"https://drive.google.com/uc?export=download&id=1oGDf1wjWp5RF_X9C7HoedhIWMh5uJs8s",
);
const body = new Uint8Array(await res.arrayBuffer());
let list = await new TextDecoder("utf-8").decode(body).split(/\r\n|\r|\n/g);
list = await list
.filter((line: string, index: number) => { // skip first two header lines
return index > 1;
});
list = await list
.filter((word: string) => {
const match = word.match(rex);
if (null !== match) {
const vowelcount = match.length;
const consonantcount = word.length - vowelcount;
if (vowelcount % 2 === 0) {
if (vowelcount / 2 * 3 === consonantcount) {
return true;
}
}
}
return false;
});
await list.forEach((line: string) => {
console.log(line);
});
That code solves a question at Quora. I've put await in a few places. How many of them are irrelevant?
No messages yet