Gabriele Ferro Home

Dev Advent Calendar – Day #07

Yesterday we helped Santa Claus writing his list, but today we discovered that some of our gifts fell from the delivery truck and this accident caused some name tags to be smudged in a way that some of the letters are not recognized anymore.

The illegible letters have been replaced with a # symbol. Our mission today is to write a function that allows us to fix illegible names on labels.

Here is my code with the output.

import names from '../data/names.js'
export const matchedNames = smudgedName => {
    const possibleNames = [];
    const myRegex = smudgedName.replace(/#/g, '.');
    names.forEach(name => {
        if (name.match(myRegex) && name.length === myRegex.length) {
            possibleNames.push(name);
        }
    });
    return possibleNames;
}

HOW TO PARTICIPATE

  1. Click the participation link
  2. Clone your repository
  3. Solve the puzzle
  4. Test your solution
  5. Add your Twitter handle
  6. Git push your changes

February 2024
MTWTFSS
 1234
567891011
12131415161718
19202122232425
26272829 

Archives

Gabriele Ferro Home
Copyright © Ferro Gabriele. All rights reserved.