-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathHexagonalNumber.js
More file actions
21 lines (19 loc) · 679 Bytes
/
HexagonalNumber.js
File metadata and controls
21 lines (19 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
* Author: Akshay Dubey (https://github.com/itsAkshayDubey)
* Hexagonal Number: https://un5qgjbzw9dxcq3ecfxberhh.julianrbryant.com/wiki/Hexagonal_number
* The nth hexagonal number hn is the number of distinct dots in a pattern of dots
* consisting of the outlines of regular hexagons with sides up to n dots, when the
* hexagons are overlaid so that they share one vertex.
*/
/**
* @function hexagonalNumber
* @description -> returns nth hexagonal number
* @param {Integer} number
* @returns {Integer} nth hexagonal number
*/
export const hexagonalNumber = (number) => {
if (number <= 0) {
throw new Error('Number must be greater than zero.')
}
return number * (2 * number - 1)
}