← Back to challenges

Consecutive Sum Check

JavaScriptHardmathnumberslogicvalidationbit_operations

Instructions

Create a function that takes a number n as an argument and checks whether the given number can be expressed as a sum of two or more consecutive positive numbers.

Examples

consecutiveSum(9) ➞ true
// 9 can be expressed as a sum of (2 + 3 + 4) or (4 + 5).

consecutiveSum(10) ➞ true
// 10 can be expressed as a sum of 1 + 2 + 3 + 4.

consecutiveSum(64) ➞ false

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.