title: Count Set Bits In An Integer 3
signature: function countSetBitsInAnInteger3(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(6, 2);
    console.log(`TEST-0...${result}`);
  
    result = driver(58, 4);
    console.log(`TEST-1...${result}`);
  
    result = driver(90, 4);
    console.log(`TEST-2...${result}`);
  
    result = driver(69, 3);
    console.log(`TEST-3...${result}`);
  
    result = driver(15, 4);
    console.log(`TEST-4...${result}`);
  
    result = driver(54, 4);
    console.log(`TEST-5...${result}`);
  
    result = driver(60, 4);
    console.log(`TEST-6...${result}`);
  
    result = driver(51, 4);
    console.log(`TEST-7...${result}`);
  
    result = driver(46, 4);
    console.log(`TEST-8...${result}`);
  
    result = driver(91, 5);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
source_py: def count_set_bits_in_an_integer_3(n):
      if (n == 0):
          return 0
      else:
          return (1 + count_set_bits_in_an_integer_3((n & (n - 1))))
source_cpp: int count_set_bits_in_an_integer_3(int n) {
    if ( n == 0 ) return 0;
    else return 1 + count_set_bits_in_an_integer_3 ( n & ( n - 1 ) );
  }