A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
19
Task/Map-range/JavaScript/map-range-2.js
Normal file
19
Task/Map-range/JavaScript/map-range-2.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
var mapRange = function(from, to, s) {
|
||||
// mapRange expects ranges generated by _.range
|
||||
var a1 = from[0];
|
||||
var a2 = from[from.length - 1];
|
||||
var b1 = to[0];
|
||||
var b2 = to[to.length - 1];
|
||||
return b1 + (s - a1) * (b2 - b1) / (a2 - a1);
|
||||
};
|
||||
|
||||
// The range function is exclusive
|
||||
var fromRange = _.range(0, 11);
|
||||
var toRange = _.range(-1, 1);
|
||||
|
||||
// .map constructs a new array
|
||||
fromRange = fromRange.map(function(s) {
|
||||
return mapRange(fromRange, toRange, s);
|
||||
});
|
||||
|
||||
console.log(fromRange);
|
||||
Loading…
Add table
Add a link
Reference in a new issue