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));
}