diff --git a/lib/lang/english.js b/lib/lang/english.js index 3fd81a4a..0c497bf4 100644 --- a/lib/lang/english.js +++ b/lib/lang/english.js @@ -1,13 +1,14 @@ -function shared_prefix_length(a, b) { - var i = 0; - while(i !== a.length && i !== b.length && a.charCodeAt(i) === b.charCodeAt(i)) - ++i; - return i; -} +function join_with_shared_prefix(joiner) { + return function(a, b) { + var i = 0; + + while(i !== a.length && + i !== b.length && + a.charCodeAt(i) === b.charCodeAt(i)) + ++i; -function join_with_shared_prefix(a, b, joiner) { - var length = shared_prefix_length(a, b); - return a.slice(0, length) + a.slice(length) + joiner + b.slice(length); + return a.slice(0, i) + a.slice(i) + joiner + b.slice(i); + }; } module.exports = require("../template")({ @@ -69,12 +70,8 @@ module.exports = require("../template")({ "minutes": "$1 min.", "fahrenheit": "$1\u00B0F", "celsius": "$1\u00B0C", - "and": function(a, b) { - return join_with_shared_prefix(a, b, " and "); - }, - "range": function(a, b) { - return join_with_shared_prefix(a, b, " through "); - }, + "and": join_with_shared_prefix(" and "), + "range": join_with_shared_prefix(" through "), "then": "$1, then $2", "clauses": function(one, two) { return one +