inRange

源码

https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/number/inRange

说明

检查指定值是否在 start end 之间, 但是不包括 end

用法

inRange.ts
inRange.test.ts
import { inRange } from "./ddzy/utility/number/inRange";
// ?
const s1 = [
{
value: 0,
start: 100,
end: 200,
},
{
value: 45,
start: -11,
end: 98,
},
{
value: 34,
start: 34,
end: 34,
},
{
value: 0,
start: -344,
end: 0,
},
];
s1.forEach((v) => {
const result = inRange(v.value, v.start, v.end);
console.log(result);
});
import { inRange } from "../../utility/number/inRange";
describe('inRange tests...', () => {
test('method inRange should compute the correct result', () => {
const received = [
{
value: 0,
start: 100,
end: 200,
},
{
value: 45,
start: -11,
end: 98,
},
{
value: 34,
start: 34,
end: 34,
},
{
value: 0,
start: -344,
end: 0,
},
];
const expected = [false, true, false, false];
received.forEach((v, i) => {
const result = inRange(v.value, v.start, v.end);
expect(result).toBe(expected[i]);
});
});
});