JSFiddle - React, Tailwind, and code Playground
JavaScript
function move(sourceLocation, targetLocation, length) {
var dist = Math.abs(targetLocation - sourceLocation);
var direction = sourceLocation < targetLocation ? 1 : -1;
if (dist < length / 2) {
console.log('internally, direction =', direction);
} else {
console.log('wrap, direction =', -direction);
}
}
move(5, 0, 6);
move(5, 3, 6);