Answers for "function that counts 1 in strings"

0

function that counts 1 in strings

function count(str) {
  var countForZero = 0;
  var countForOne = 0;
    
  for (var i = 0, length = str.length; i < length; i++) {
    if (str[i] === '0') {
      countForZero++;
    }
    else {
      countForOne++;
    }
  }
    
  return {
    'zero': countForZero,
    'One': countForOne
  };
}
Posted by: Guest on July-29-2021
0

function that counts 1 in strings

int grey (const char* cStr) {
	int c = 0;
	if (*cStr != '\0') {
			if (*cStr == '1') c++;
			c = c+grey(cStr + 1);
	}
	return c;
}

int main {
	cout << grey("0110101100110") << '\n'; // Skriver ut 7
}
Posted by: Guest on July-29-2021

Code answers related to "function that counts 1 in strings"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language