Skip to content

Instantly share code, notes, and snippets.

@kitcat-dev
Created August 28, 2019 07:56
Show Gist options
  • Select an option

  • Save kitcat-dev/ba421e1d028409ac33f79e99b3a2fa23 to your computer and use it in GitHub Desktop.

Select an option

Save kitcat-dev/ba421e1d028409ac33f79e99b3a2fa23 to your computer and use it in GitHub Desktop.

Revisions

  1. kitcat-dev created this gist Aug 28, 2019.
    17 changes: 17 additions & 0 deletions partialApply.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    const partialApply = (fn, arg1) => (arg2, arg3) => fn(arg1, arg2, arg3);

    const getAverageSalary = (profession, country) => {
    if (profession === 'programmer') {
    if (country === 'spain') return 2000;
    if (country === 'russia') return 1200;
    if (country === 'usa') return 8000;
    }
    }

    const getProgrammersSalaryByCountry = partialApply(getAverageSalary, 'programmer');

    const salary1 = getProgrammersSalaryByCountry('spain');
    const salary2 = getProgrammersSalaryByCountry('russia');
    const salary3 = getProgrammersSalaryByCountry('usa');

    console.log(salary1, salary2, salary3)