← Back to challenges

Count the Lone Ones

JavaScriptHardalgorithmsloopsnumbersregex

Instructions

Create a function which counts how many lone 1s appear in a given number. Lone means the number doesn't appear twice or more in a row.

Examples

countLoneOnes(101) ➞ 2

countLoneOnes(1191) ➞ 1

countLoneOnes(1111) ➞ 0

countLoneOnes(462) ➞ 0

Notes

Tests will include positive whole numbers only.

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