1
var shortestCompletingWord = function (licensePlate, words) {2
// Object to hold the shortest word that matches3
var match = { found: false, word: "" };5
// Char array to hold the upper case characters we want to match6
var licensePlateChars = licensePlate8
.replace(/[^A-Z]/g, "")11
words.forEach(function (word) {12
// if we already have a match make sure that the word we are checking is shorter13
if (!match.found || word.length < match.word.length) {14
var replaceWord = word.toUpperCase();16
// Loop over each character in the license plate and replace one at a time17
// the key here is that replace will only replace 1 S even if there are 218
licensePlateChars.forEach(function (lChar) {19
replaceWord = replaceWord.replace(lChar, "");22
// We know the word works if the length of the word minus23
// the length of chars equals the length of the new word24
if (word.length - licensePlateChars.length === replaceWord.length) {