Scrambled Letters

Published by Edward Clark in

Write a function that receives an array of letters, an array of words (dictionary) and a mask. Return an array of words, sorted alphabetically, that match the given mask.

Examples

scrambled(['e', 'c', 'd', 'r', 'e', 'e'], [”red”, “dee”, “cede”, “reed”, “creed”, “decree”], “*re**”) ➞ [“creed”]

scrambled(['e', 'c', 'd', 'r', 'e', 'e'], [”red”, “dee”, “cede”, “reed”, “creed”, “decree”], “***”) ➞ [“dee”, “ree”]

Notes

The length of a mask will never exceed the number of letters given (or the longest word in the dictionary).

Watch a quick demo on how Edabit works.