Skip to content Skip to sidebar Skip to footer

Compare Difference Between Multiple Numbers

The problem is that I have array with 5 numbers: 300 295 250 105 100 95 The result needed: the most numbers that have least difference specified by threshold. If you cant

Solution 1:

I cannot give Javascript code, but I propose:

  • Sort the list
  • Compute sequential differences
  • round or clip any values below threshold to zero, and all others to one
  • look for the longest continuous sequence of zeros (run-length encoding)
{95, 100, 105, 250, 295, 300}

--->  {5, 5, 145, 45, 5}

--->  {0, 0, 1, 1, 0}

Post a Comment for "Compare Difference Between Multiple Numbers"