<<<<<<< HEAD Code Wars - Brett Crafton

Grasshopper - Summation

Question

Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0. For example:

summation(2) -> 3 1 + 2 summation(8) -> 36 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8

Solution by -

My Solution


	var summation = function (num) {
		return num*(num+1) / 2
		}

		or 

	var summation = function (num) {
		let result = 0
		for(let i = 0; i <= num; i++){
		result += i
		}
		return result
		}
				

Try it yourself - CodeWars

======= Code Wars - Brett Crafton

Grasshopper - Summation

Question

Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0. For example:

summation(2) -> 3 1 + 2 summation(8) -> 36 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8

Solution by -

My Solution


	var summation = function (num) {
		return num*(num+1) / 2
		}

		or 

	var summation = function (num) {
		let result = 0
		for(let i = 0; i <= num; i++){
		result += i
		}
		return result
		}
				

Try it yourself - CodeWars

>>>>>>> 0e614172debaa009c8d31330edbeb3b765b59c39