boxes/js/utils/range.mjs

28 lines
473 B
JavaScript
Raw Normal View History

export function is_in_range (number, min, max) {
2023-06-23 09:00:12 +00:00
return number >= min && number <= max;
}
export function clamp (number, min, max) {
2023-06-23 09:00:12 +00:00
return number < min
? min
: number > max
? max
: number;
}
export function range (start, end) {
2023-06-23 09:00:12 +00:00
const result = [];
for (let n = start; n <= end; n++) {
result.push(n);
}
return result;
}
export function iter_2d (range_1d, callback) {
for (const y in range_1d) {
for (const x in range_1d) {
callback(x, y);
}
}
}