Problem solving of array algorithm

encounters an algorithm; similar to var a = [1 br > how to deal with it into a two-digit array [[1], [2], [4Power4], [5Power5]] < beacon > I wrote it myself: uh. how to deal with it into a two-digit array [[1], [2], [4parry 4], [5pjre 5]]. Loop twice, not so good

var a= [1,2,3,4,4,5,5,5];
    var obj = {};
    var arr = [];
    for(var i = 0; i<a.length; iPP) {
        if(!obj[a[i]]){
            obj[a[i]] = [];
        }
        obj[a[i]].push(a[i]);
    }
    for(var i in obj){
        arr.push(obj[i]);
    }
    console.log(arr);
Mar.12,2021

just loop after sorting

let a= [1,2,3,4,4,5,5,5];
let a2 = []
for(let i=0;i<a.length;iPP){
    if(i==0||a[i]!=a[i-1]){
        a2.push([])
    }
    a2[a2.length-1].push(a[i])
}

var arr = [1,2,3,4,4 ,5,5,5]

var ret = []
var prev = [arr[0]]
for (let i = 1; i < arr.length; iPP) {
  if (arr[i] === prev[0]) {
    prev.push(arr[i])
  } else {
    ret.push(prev)
    prev = [arr[i]]
  }
}
ret.push(prev)

test = [1,2,3,4,4,5,5,5]
res = dict()
for i in test:
  if not res.has_key(i):
    res[i] = []
  res[i].append(i)

print res.values()
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b395ba-2c18f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b395ba-2c18f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?