const countBits = function(num) {
    const result = [0]; // Initialize the result array with 0
    
    for (let i = 1; i <= num; i++) {
        // Use bitwise AND operation to count bits
        result[i] = result[i >> 1] + (i & 1);
    }
    
    return result;
};
 
// Example usage:
const num = 5;
console.log(countBits(num)); // Output: [0, 1, 1, 2, 1, 2]