Check three consecutive numbers - JavaScript

We are required to write a JavaScript function that takes in a Number, say n, and we are required to check whether there exist such three consecutive natural numbers (not decimal/floating point) whose sum equals to n.

If there exist such numbers, our function should return them, otherwise it should return false. Following is the code −

Example

const sum = 54;
const threeConsecutiveSum = sum => {
   if(sum 

Output

Following is the output in the console −

[ 17, 18, 19 ]
Updated on: 2020-09-15T11:59:47+05:30

520 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements