forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHexagonalNumber.js
More file actions
Latest commit
21 lines (19 loc) · 679 Bytes
/
Copy pathHexagonalNumber.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://en.wikipedia.org/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
*/
exportconsthexagonalNumber=(number)=>{
if(number<=0){
thrownewError('Number must be greater than zero.')
}
returnnumber*(2*number-1)
}