How to quickly convert an array?

let a =[1,2,3,4,5];

let b = [[1,2],[3,4],5]

how to quickly implement the above a-> b operation?

Mar.31,2021

function piecewise(ary, size) {
    var ary = ary.slice()
        len = ary.length,
        retAry = []

    if ( len < size ) {
        return [ary];
    }


    var count = Math.floor(len / size) + (len % size == 0 ? 0 : 1)

    while(count--) {
        retAry.push(ary.splice(0, size))
    }

    return retAry
}

var ary = [1,2,3,4,5]
piecewise(ary, 2) 

I hope it will be helpful to you

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-1b3bfd5-4d977.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-1b3bfd5-4d977.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?