I would like to create sub arrays of **[10,10,10,10,10,10,10,10,10,4,4,4]** that sum of each sub array is **not** greater than 100, so the result should be **[[10,10,10,10,10,10,10,10,10,4,4],[4]]**

I tried below, but not work not sure where the problem is at

```
   const arr=[10,10,10,10,10,10,10,10,10,4,4,4]

    const result=[]

    let sum=0
    let temp=[]

    for(let i=0; i<arr.length;i++){
      if(sum+arr[i]<=100){
        sum+=arr[i]
        temp.push(arr[i])
      }else{
         result.push(temp)
         sum=0
         temp.length=0

         temp.push(arr[i])
         sum+=arr[i]
      }
    }

console.log(result) //[ [ 4 ] ]

```