summaryrefslogtreecommitdiff
path: root/src/modules/Util.js
blob: 2375f108b94846cd4a463f6a7ce4333a0d581613 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function useAverage() {
	var avg = 0;
	let weight = 0;
	const append = value => {
		avg = (weight * avg) + value;
		weight += 1;
		avg = avg/weight;
	}

	return [() => avg, append];
}

function clamp(value, min, max) {
	return Math.min(Math.max(value, min), max);
}

export { useAverage, clamp };