Obtener brecha binaria en JS

let N = 9;
const Binary = N.toString(2); // "1001"
const BinaryArray = Binary.split(''); // ["1", "0", "0", "1"]
// finding the first one via its index
const firstOne = BinaryArray.indexOf("1"); // 0 = Index of array
// new array created taking a slice of original array 
// from the index of the firstOne + 1 index
let NewBinaryArray = BinaryArray.slice(firstOne + 1); 
// ["0", "0", "1"]
// finding second one via its index in new array slice
const secondOne = NewBinaryArray.indexOf("1"); // 2
// where we store our gaps
const gaps = [];
// adding 2 to our gaps array
gaps.push(secondOne); // [2]
// getting largest value in array
return Math.max.apply(Math, gaps); // 2
Worrisome Wolverine