Source: Codewars

The Challenge: The marketing team is spending way too much time typing in hashtags. Let's help them with our own Hashtag Generator! Here's the deal:

function generateHashtag(str) {
  if (!str) {
    return false;
  }
  let hashtag = "#";
  for (let x = 0; x < str.length; x++) {
    if (str[x] !== " ") {
      if (x === 0) {
        hashtag = hashtag + str[x].toUpperCase();
      } else if (str[x - 1] === " ") {
        hashtag = hashtag + str[x].toUpperCase();
      } else {
        hashtag = hashtag + str[x];
      }
    }
  }
  if (hashtag.length === 1 || hashtag.length > 140) {
    return false;
  }
  return hashtag;
}

projects · about · cv · home