@adriaangijssen/

DimpledDirectAddon

Nodejs

No description

fork
loading
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function recurseSum (list){
  if (list.length < 2) {
    return list;
  } else {
    let leftList = [];
    let rightList = [];
    const pivotList = [];
    const pivot = list[0]
    for (let x=0; x < list.length; x++) {
      if(list[x] < pivot) {
        leftList.push(list[x]);
      } else if (list[x] === pivot) {
        pivotList.push(list[x]);
      } else {
        rightList.push(list[x]);
      }
    }
    leftList = recurseSum(leftList);
    rightList = recurseSum(rightList);
    for (let y = 0; y < pivotList.length; y++) {
      leftList.push(pivotList[y]);
    }
    for (let z = 0; z < rightList.length; z++) {
      leftList.push(rightList[z]);
    }
    return leftList;
  }
}

console.log(recurseSum([5,4,1,5,7,9,4]).toString());
node v10.16.0