1
0
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:
Alain Pitiot 2023-07-19 09:50:55 +02:00 committed by GitHub
commit 324fa88a7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.
*