/readable-operators

JS operators as functions. May be passed as parameters and improves readability.

Primary LanguageJavaScript

readable-operators

JS operators as functions. May be passed as parameters and improves readability.

Installing

Yarn:

  • bash yarn add readable-operators

NPM:

  • bash npm i readable-operators

Examples

Passing as parameter

    const ro = require("readable-operator"); 

    let applyOperator = (operator, a, b) => 
    {
        return operator(a, b); 
    }

    console.log(applyOperator(ro.add, 10, 5)) // 15
    console.log(applyOperator(ro.subtract, 10, 5)) // 5

Making things readable

    const ro = require("readable-operator"); 

    // The answer was correct 
    if(answer.isCorrect())
    {
        ro.add(score, 1); 
    } else 
    {
        ro.subtract(score, 1); 
    }

Running tests

yarn test