1
0
mirror of https://github.com/psychopy/psychojs.git synced 2025-05-10 10:40:54 +00:00

add linspace to util.js

This commit is contained in:
RebeccaHirst 2022-01-06 16:39:08 +00:00
parent 2f072ebb9f
commit 96903e0266

View File

@ -358,6 +358,24 @@ export function shuffle(array, randomNumberGenerator = undefined)
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.
*