UNPKG

sum_of_1_n_numbers_rntm

Version:

Calculates the sum of 1-n numbers

12 lines (9 loc) 235 B
module.exports = function sum(n) { try { const num = Number(n); if (num <= 0) throw "Number is smaller than 0."; return (num * (num - 1)) / 2; } catch (error) { throw error; } }