This solution is generated by ChatGPT, correctness is not guaranteed.

AI solution for JavaScript Coding Question on BFE.dev
10. first bad version

function firstBadVersion(n) { let left = 1; let right = n;

while (left < right) { let mid = Math.floor((left + right) / 2); if (isBad(mid)) { right = mid; } else { left = mid + 1; } }

return isBad(left) ? left : -1; }

// example usage // suppose we have 10 versions let n = 10;

// we are given a function isBad that returns true if a version is bad and false if it's not function isBad(version) { return version >= 4; }

console.log(firstBadVersion(n)); // expected output: 4