title: Count Set Bits In An Integer 1
signature: function countSetBitsInAnInteger1(n: number): number {
test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(n: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(n),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver(43, 4);
    console.log(`TEST-0...${result}`);
  
    result = driver(94, 5);
    console.log(`TEST-1...${result}`);
  
    result = driver(72, 2);
    console.log(`TEST-2...${result}`);
  
    result = driver(86, 4);
    console.log(`TEST-3...${result}`);
  
    result = driver(42, 3);
    console.log(`TEST-4...${result}`);
  
    result = driver(33, 2);
    console.log(`TEST-5...${result}`);
  
    result = driver(8, 1);
    console.log(`TEST-6...${result}`);
  
    result = driver(74, 3);
    console.log(`TEST-7...${result}`);
  
    result = driver(29, 4);
    console.log(`TEST-8...${result}`);
  
    result = driver(34, 2);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
source_py: def count_set_bits_in_an_integer_1(n):
      if (n == 0):
          return 0
      else:
          return ((n & 1) + count_set_bits_in_an_integer_1((n >> 1)))
source_cpp: int count_set_bits_in_an_integer_1(int n) {
    if ( n == 0 ) return 0;
    else return ( n & 1 ) + count_set_bits_in_an_integer_1 ( n >> 1 );
  }