20 lines
390 B
JavaScript
20 lines
390 B
JavaScript
const applyOffset = (from, to) => {
|
|
let hasReceivedFrom = true;
|
|
if (to === undefined) {
|
|
to = from;
|
|
hasReceivedFrom = false;
|
|
}
|
|
return (v) => {
|
|
if (hasReceivedFrom) {
|
|
return v - from + to;
|
|
}
|
|
else {
|
|
from = v;
|
|
hasReceivedFrom = true;
|
|
return to;
|
|
}
|
|
};
|
|
};
|
|
|
|
export { applyOffset };
|