Sum of numbers from 0 to N

JavaScript

var SequenceSum = (function() {
  function SequenceSum() {}

  SequenceSum.showSequence = function(count) {
    if (count < 0) return count + "<" + 0;
    if (count == 0) return count + "=" + 0;

    let sum = 0, str = "";
    for (let i = 0; i <= count; i++) {
      sum += count;
      str += i + ((i != count) ? "+" : " = " + sum / 2);
    }

    return str;
  };

  return SequenceSum;

})();

Tags

  1. javascript (Private)
  2. 7-kyu (Private)
  3. codewars (Private)
  4. answer (Private)