JSFiddle - React, Tailwind, and code Playground

by HemalathaThanigaivel

JavaScript

var list = [16, 20, 1, 4, 6, 8, 9, 22, 18, 14, 13, 12], i
    result = [];
// considering ranges `1-4, 5-8, 9-12, 13-16, 17-20, 21-24`
for (i = 1; i < 24; i+= 1) {
  result.push(list.filter(function(d){
    return ((i+4 > d) && d >= i);  // check if the number between lower and upper bound
  }));
}

console.log(result);