mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-10 10:40:54 +00:00
Merge pull request #470 from RebeccaHirst/_addLinspace
add linspace to util.js
This commit is contained in:
commit
324fa88a7a
@ -362,6 +362,24 @@ export function shuffle(array, randomNumberGenerator = undefined, startIndex = u
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* linspace
|
||||
*
|
||||
* @name module:util.linspace
|
||||
* @function
|
||||
* @public
|
||||
* @param {Object[]} startValue, stopValue, cardinality
|
||||
* @return {Object[]} an array from startValue to stopValue with cardinality steps
|
||||
*/
|
||||
export function linspace(startValue, stopValue, cardinality) {
|
||||
var arr = [];
|
||||
var step = (stopValue - startValue) / (cardinality - 1);
|
||||
for (var i = 0; i < cardinality; i++) {
|
||||
arr.push(startValue + (step * i));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick a random value from an array, uses `util.shuffle` to shuffle the array and returns the last value.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user