Skip to content

Instantly share code, notes, and snippets.

@enijar
Created February 5, 2020 22:43
Show Gist options
  • Select an option

  • Save enijar/add594f27f0734943b6c55efb610d087 to your computer and use it in GitHub Desktop.

Select an option

Save enijar/add594f27f0734943b6c55efb610d087 to your computer and use it in GitHub Desktop.

Revisions

  1. enijar created this gist Feb 5, 2020.
    8 changes: 8 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    Takes a value from range (x1, y1) and maps that value to a new range (x2, y2).

    ```javascript
    const map = (value, x1, y1, x2, y2) => (value - x1) * (y2 - x2) / (y1 - x1) + x2;

    const value = 5; // range (1, 10)
    console.log(map(value, 1, 10, 0, 1)); // 0.5
    ```