Skip to content

Instantly share code, notes, and snippets.

@esase
Created March 25, 2022 17:20
Show Gist options
  • Save esase/f9d0e6d453e9d51201546d66796a3556 to your computer and use it in GitHub Desktop.
Save esase/f9d0e6d453e9d51201546d66796a3556 to your computer and use it in GitHub Desktop.
/**
* @param {number} startValue
* @param {number} target
* @return {number}
*/
var brokenCalc = function(startValue, target) {
let steps = 0;
while (startValue < target) {
steps++;
if (target % 2) {
target++;
continue;
}
target /= 2;
}
// process the rest
return startValue - target + steps;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment