function wordToDigits(input) {
let result = "";
while (input.length) {
const match = input.match(
/^(one|two|three|four|five|six|seven|eight|nine|\d)/
);
if (match) {
const i = parseInt(match[0]);
if (isNaN(i)) {
result += digits[match[0]];
} else {
result += i;
}
} else {
result += input[0];
}
input = input.slice(1);
}
return result;
}