Broken Calculator LeetCode solution in JavaScript

1
/**
2
* @param {number} startValue
3
* @param {number} target
4
* @return {number}
5
*/
6
var brokenCalc = function (startValue, target) {
7
let steps = 0;
8

9
while (target !== startValue) {
10
if (startValue > target) {
11
return steps + startValue - target;
12
}
13
if (target % 2 === 0) {
14
target /= 2;
15
} else {
16
target += 1;
17
}
18
steps++;
19
}
20
return steps;
21
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0