DEV Community

Bruce Axtens
Bruce Axtens

Posted on • Edited on

Learning Deno and liking what I see

Today I learned why there's some buzz going on about Deno. As someone who has always found Node difficult, Deno is a welcome relief.

Recently I started solving some computable problems on Quora using C#. One of them was What are words with a vowel to consonant ration of 2:3?. Below is Deno code re-implementing the C#. Please note that the word-list in the Deno solution is different from that of the C# version (https://boardgames.stackexchange.com/questions/38366/latest-collins-scrabble-words-list-in-text-file rather than https://users.cs.duke.edu/~ola/ap/linuxwords).

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());

const list = await new TextDecoder("utf-8").decode(body).split(/\r\n|\r|\n/g)
  .filter((line: string, index: number) => { // skip first two header lines
    return index > 1;
  })
  .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;
  });

list.forEach((line: string) => {
  console.log(line);
});
Enter fullscreen mode Exit fullscreen mode

There are probably better way to write that, but the await notation seemed fairly natural and made sense. Being able to use .filter was helpful too.

I think I'm going to enjoy learning Deno. Maybe you will too.

Top comments (0)