JSFiddle - React, Tailwind, and code Playground

by Fabio Dan

JavaScript

// camelCase • Return the number of words

let camelCase = "fdsaFfdafasdFfdasfas";

function countWords(str) {
	let wordCount = 1; // Because first word is all lowercase (camelCase)
  
  for (let i = 0; i < str.length; i++) {
  	let letter = str[i];
    
  	if (letter == letter.toUpperCase()) {
    	wordCount++;
    }
  }

	return wordCount;
}

console.log(countWords(camelCase));