code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

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:27:46+05:30 · Edit