How to rewrite this function as a pure function?

I have this function

function sumUpToNum(num) {
  let sum = 0;
  for(let z=0;z<num;z++) {
    sum+=z;
  }
  return sum;
}

How to rewrite as a pure function? What i have tried:

function sumUpToNum(num) {
    let sum = 0;
    while(num--) {
      sum+=num;
    }
    return sum;
}