code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

028 Chunky Monkey

/**
 * 
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

function chunkyMonkey(array, n) {
  if(array.length <= n){
    return [array]
  }
  return [array.slice(0,n)].concat(chunkyMonkey(array.slice(n), n))
}

console.log(JSON.stringify(chunkyMonkey([0,1,2,3,4,5], 4)))

// test('chunky Monkey', () => {
//   expect(chunkyMonkey('Ashish')).toEqual('Ashish')
// });

Created 2019-12-09T03:15:46+05:18 · Edit