DEV Community

Discussion on: How would you refactor this JS function?

Collapse
 
senthilkumaranc profile image
SenthilKumaranC • Edited

I have refactored like below. Divided all conditions to Spec Units and Grouped Spec Units. Check my Github Link to see my code.


const specApis = specificationGroup();

specApis.addSpecObject(headerSpecGroup, headerSpecGroupCallback);
specApis.addSpecObject(paragraphSpecGroup, paragraphSpecGroupCallback);
specApis.addSpecObject(isEmpty, breakSpecGroupCallback);

export const lineChecker = (line, isFirstLine) => {
    let initialDocument = "";
    return specApis.validateSpecs({ initialDocument, line, isFirstLine });
}

Enter fullscreen mode Exit fullscreen mode

github.com/SenthilKumaranC/How-To-...