Skip to content

Commit

Permalink
Metaprogramming cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason LaPorte committed Jul 25, 2013
1 parent c575d81 commit 6910455
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions lib/lang/english.js
Original file line number Diff line number Diff line change
@@ -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")({
Expand Down Expand Up @@ -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 +
Expand Down

0 comments on commit 6910455

Please sign in to comment.