Giter Club home page Giter Club logo

wh-takehome's Introduction

Weekend Health Take Home Challenge

Problem Statment

Implement a function named findWords that accepts two arguments: 1) an input string and 2) a dictionary. This function should return an array of words from the dictionary that can be formed by rearranging some or all of the letters in the input string. Each letter in the input string may be used up to once per word.

function findWords(inputString: string, dictionary:string[]): string[]

Running the function

  1. npm install
  2. npm start

Approach

Also copied in the code, but added here as well.

  1. We should first check for a valid input, and a valid dictionary.

  2. The input could also be made lowercase and whitespace trimmed

  3. Now we need to keep track of the letters in the input words, as well as their counts since each letter could only be used once.

    a. One approach would be to create an array of letters from the word and pop them out as we iterate through each word in the dict.

    We'll also need to reset the original word for each iteration of the dictionary loop. This would be a little inefficient because there would a function call to create the word. There would also need to a call to arr.splice().

    b. Another approach to do this would to be to count the letter frequency in the input word and compare that against the letter frequency of the word in the dictionary. If the character doesn't exist we can break out of the loop, otherwise continue until all letters of the dictionary word have been checked.

  4. Another thing to handle would be situations with one letter, for correctness.. the only 2 words in the english language are "a" and "I" but that should work since we are filtering out words that are longer than the input.

TODOs for the future

  • Add more test cases and benchmark performance of 2
  • Sanitize inputs for illegal characters

wh-takehome's People

Contributors

chmaltsp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.