JSFiddle - React, Tailwind, and code Playground
by LyndseyB
Babel + JSX
// import getDictionary from './getDictionary';
const solver = function(customDictionary = []) {
if(!Array.isArray(customDictionary)) {
throw('Custom dictionary should be an array with at least one value');
}
const getDictionary = function() {
return ['one', 'two'];
};
const isCustomDictionary = customDictionary.length > 0;
const dictionary = isCustomDictionary ? customDictionary : getDictionary();
return {
solve() {
return dictionary;
},
};
};
const mySolver = solver();
console.log(mySolver.solve('ajsadf'));
const mySolverCustom = solver(['three', 'four']);
console.log(mySolverCustom.solve(''));