DEV Community

Bruce Axtens
Bruce Axtens

Posted on • Edited on

3 1

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.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay