Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

substitute function does not work for numbers > 9 #344

Open
huwred opened this issue Sep 27, 2018 · 1 comment
Open

substitute function does not work for numbers > 9 #344

huwred opened this issue Sep 27, 2018 · 1 comment

Comments

@huwred
Copy link

huwred commented Sep 27, 2018

The substitute function fails if the number is > 9 i.e 10 20 etc.
fix:
function substitute(stringOrFunction, number) {
var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
var digits = number.toString(10).split("").map(Number);
var resultnumber = "";
digits.forEach(function (entry) {
var value = ($l.numbers && $l.numbers[entry]) || number;
if (value === number) {
resultnumber = value;
} else {
resultnumber += value;
}
});
return string.replace(/%d/gi, resultnumber);
}

@msftrncs
Copy link

@huwred, I think you are supposed to specify the numbers for all possible values. Its not named digits.

ie, '21' -> 'twenty-one'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants