Created
July 28, 2018 09:03
-
-
Save andrIvash/c0069defb735efbdf66a192f0be29189 to your computer and use it in GitHub Desktop.
Нормирование массива до указанного диапазона
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //y[i]=(x[i]-min)/(max-min)*(b-a)+a; | |
| function normalize (arr, a, b) { | |
| const result = []; | |
| const max = Math.max(...arr); | |
| const min = Math.min(...arr); | |
| arr.forEach(elem => { | |
| result.push(+((elem-min)/(max-min)*(b-a)+a).toFixed(2)); | |
| }) | |
| return result; | |
| } | |
| console.log(normalize([0,1.5,5.6,3.2,4,2.5,10], 0, 3)); // from 0 to 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment