Find longest sequence of zeros in binary representation of an integer.
https://app.codility.com/programmers/lessons/1-iterations/binary_gap/
function solution(N) {
let binaryArray = N.toString(2).split("1"); // 2μ§μ λ³ν
let length = binaryArray.map((x) => x.length); // λ°°μ΄ μμ κΈΈμ΄ νμΈ
// κ°μ₯ κΈ΄ κΈΈμ΄ μ°ΎκΈ°
// λ°°μ΄μ΄ κΈΈμ΄κ° 2κ° μ΄ν μΌ κ²½μ° '1'κ³Ό '1' μ¬μ΄μ μλ κ²μ΄ μλλ―λ‘ 0 λ°ν
let result = binaryArray.length > 2 ? Math.max(...length) : 0;
return result;
}
function solution(N) {
const binary = N.toString(2);
const trimmed = binary.substr(0, binary.lastIndexOf("1") + 1);
return Math.max(...trimmed.split("1").map((item) => item.length));
}