Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Map-range/JavaScript/map-range-1.js
Normal file
12
Task/Map-range/JavaScript/map-range-1.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// Javascript doesn't have built-in support for ranges
|
||||
// Insted we use arrays of two elements to represent ranges
|
||||
var mapRange = function(from, to, s) {
|
||||
return to[0] + (s - from[0]) * (to[1] - to[0]) / (from[1] - from[0]);
|
||||
};
|
||||
|
||||
var range = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
for (var i = 0; i < range.length; i++) {
|
||||
range[i] = mapRange([0, 10], [-1, 0], range[i]);
|
||||
}
|
||||
|
||||
console.log(range);
|
||||
Loading…
Add table
Add a link
Reference in a new issue