You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
312 B
JavaScript

"use strict";
module.exports = function matchValue(value, arms) {
for (let [candidateValue, arm] of Object.entries(arms)) {
if (candidateValue !== "_" && value === candidateValue) {
return arm();
}
}
if (arms._ != null) {
return arms._();
} else {
throw new Error("No matching arm found");
}
};