JSFiddle - React, Tailwind, and code Playground

Drag&Drop priority algorithm

by Slava

CSS

td{padding:0 4px;white-space:nowrap;font-family:"Segoe UI",sans-serif;}
.dim{opacity:0.5;}
.condensed{font-family:"Open Sans Condensed","Ubuntu Condensed";}
.red{color:red;}
.green{color:green;}
.semibold{font-weight:600;}

JavaScript

var output = [], last='last', next='next';
var testCases = [
//[lastProcessedOrderIndex, prevOrderIndex (before change), nextProcessedOrderIndex, expected newOrderIndex, itemWasMoved, expected action]
  'Not supposed to change',
  [2.000000, 2.000000, 2.000000, 2.000000, true, 'Ignore'], // Ignore case: All zeros
  [2.400000, 2.4, 		 2.399990, 2.400000, true, 'Ignore'], // Ignore case: Zeroed top
  [2.499999, 2.499998, 2.499996, 2.499998, true, 'Ignore'], // Ignore case: Already within range
  [2.400000, 2.400000, 2.300000, 2.400000, true, 'Ignore'], // Ignore case: Will affect first decimal digit
  [    null, 3.000000,     null, 3.000000, true, 'Ignore'], // Ignore case: Undefined range (only item in the list)
  [    null, 3.000000, 2.499996, 3.000000, true, 'Ignore'], // Ignore case: Already within (topless) range
  [2.499996, 2.399999,     null, 2.399999, true, 'Ignore'], // Ignore case: Already within (bottomless) range
  [2.499995, 1.000000,     null, 1.000000, true, 'Ignore'], // Ignore case: Already within (bottomless) range
  [2.000000, 1.000000,     null, 1.000000, true, 'Ignore'], // Ignore case: Already within (bottomless) range
  [2.099998, 2.000001, 2.000000, 2.000001, true, 'Ignore'], // Ignore case: Already within range
  [3.499998, 2.300000, 1.499995, 2.300000, true, 'Ignore'], // Ignore case: Zeroed item, within range, only in group.
  [    null, 3.499998, 1.499995, 3.499998, next, 'Ignore'], // Ignore case: Not moved item, first range, only in group.
  [    null, 3.499998, 1.000000, 3.499998, next, 'Ignore'], // Ignore case: Not moved item, first range, only in group.
  
  'Supposed to change',
  [2.499999, 2.499999, 2.000000, 2.499998, true, 'Decrement'],  // Conflict. Decrement to 2.499998
  [2.499998, 2.499998, 2.499999, 2.499997, true, 'Decrement'],  // Conflict. Decrement to 2.499997
  [2.490001, 2.490001, 2.000000, 2.490000, true, 'Decrement'],  // Conflict. Decrement to 2.490000
  [2.499998, 3.000000, 2.499995, 2.499997, true,...