compromise
Version:
natural language processing in the browser
25 lines (22 loc) • 540 B
JavaScript
;
const words = require('./data');
//concatenate into a string with leading '0.'
const parseDecimals = function(arr) {
let str = '0.';
for (let i = 0; i < arr.length; i++) {
let w = arr[i];
if (words.ones[w]) {
str += words.ones[w];
} else if (words.teens[w]) {
str += words.teens[w];
} else if (words.tens[w]) {
str += words.tens[w];
} else if (w.match(/^[0-9]$/)) {
str += w;
} else {
return 0;
}
}
return parseFloat(str);
};
module.exports = parseDecimals;