text: function countVowels(str) {
    if (!str) return 0;
    str = str.toLowerCase();
    let vowels = ['a', 'e', 'i', 'o', 'u'];
    let count = 0;
    for (let i = 0; i < str.length; i++) {
      if (vowels.includes(str[i])) count++;
    }
    return count;
  }
  
  function reverseString(str) {
    return str.split('').reverse().join('');
  
    /*-------- Alternative -------*/
  
    // if (!str) return '';
    // let result = [];
    // for (let i = str.length - 1; i >= 0; i--) {
    //   result.push(str[i]);
    // }
    // return result.join('');
  }
  
  function reverseWords(str) {
    return str.split(' ').reverse().join(' ');
  
    /*-------- Alternative -------*/
  
    // let stack = [];
    // let word = '';
  
    // for (let i = 0; i < str.length; i++) {
    //   while (i < str.length && str[i] != ' ') {
    //     word += str[i];
    //     i++;
    //   }
    //   stack.push(word);
    //   word = '';
    // }
    // return stack.reverse().join(' ');
  }
  
  function areRotations(str1, str2) {
    if (str1.length != str2.length) return false;
    let len = str1.length;
    if (len > 500000) return traverse();
    else return (str1 + str1).includes(str2);
  
    function traverse() {
      let count = 0;
      let start = str2.indexOf(str1[0]);
  
      while (count < len) {
        if (start == -1) return false;
        if (str1[count] == str2[(start + count) % len]) {
          count++;
          continue;
        }
        start = str2.indexOf(str1[0], start + 1);
        count = 0;
      }
      return true;
    }
  }
  
  function removeDuplicateChars(str) {
    let unique = new Set();
    let result = [];
    for (let i = 0; i < str.length; i++) {
      if (!unique.has(str[i])) {
        unique.add(str[i]);
        result.push(str[i]);
      }
    }
    return result.join('');
  }
  
  function mostRepeatedChar(str) {
    let counts = [],
      chars = [];
    for (let i = 0; i < str.length; i++) {
      let char = str[i];
      if (chars.includes(char)) {
        let index = chars.indexOf(char);
        counts[index]++;
      } else {
        chars.push(char);
        counts.push(1);
      }
    }
    let max = Math.max.apply(null, counts);
    let index = counts.indexOf(max);
    return `'${chars[index]}'`;
  }
  
  function capitalizeFirstLetters(str) {
    if (!str) throw new Error('parameter is not valid.');
    str = str.replace(/\s+/g, ' ');
    return str.replace(/\b\w/g, (ch) => ch.toUpperCase());
  
    /*-------- Alternative -------*/
  
    // let words = [];
  
    // for (let i = 0; i < str.length; i++) {
    //   let word = [];
    //   while (str[i] != ' ' && i < str.length) {
    //     word.push(str[i]);
    //     i++;
    //   }
    //   if (!word.length) continue;
    //   word = word.map((ch, i) => !i ? ch.toUpperCase() : ch.toLowerCase());
    //   words.push(word.join(''));
    // }
    // return `'${words.join(' ')}'`;
  }
  
  function areAnagrams(str1, str2) {
    let nullish = [null, undefined];
    if (nullish.includes(str1) || nullish.includes(str2))
      throw new Error("Parameters can't be undefined or null.");
    if (str1.length != str2.length) return false;
  
    /*-------- Alternative -------*/
  
    // let first = str1.split('').sort();
    // let second = str2.split('').sort();
  
    // for (let i = 0; i < first.length; i++) {
    //   if (first[i] != second[i]) return false;
    // }
  
    let charCounts = new Map();
  
    for (let ch of str1) {
      if (!charCounts.has(ch)) {
        charCounts.set(ch, 1);
      } else charCounts.set(ch, charCounts.get(ch) + 1);
    }
  
    for (let ch of str2) {
      if (!charCounts.get(ch)) return false;
      charCounts.set(ch, charCounts.get(ch) - 1);
    }
  
    for (let key of charCounts.keys()) {
      if (charCounts.get(key) != 0) return false;
    }
  
    return true;
  }
  
  function isPalindrome(str) {
    if (str === null || str === undefined)
      throw new Error("Parameter can't be null or undefined.");
    return str == str.split('').reverse().join('');
  
    /*----------- Alternative ----------*/
  
    // let last = str.length - 1;
    // for (let i = 0; i <= last / 2; i++) {
    //   if (str[i] != str[last - i]) return false;
    // }
    // return true;
  }
  
  let str = '   WOW        these       TReeS        aRe      bEAuTIfUl         ';
  let first = 'this is this Hello World ';
  let second = ' is this Hello World this';
  let third = '  isthis Hello World this';
  let palindrome = 'kadak';
  countVowels(str); //?
  reverseString(str); //?
  reverseWords(str); //?
  removeDuplicateChars(str); //?
  areRotations(first, second); //?
  areRotations(first, third); //?
  areAnagrams(first, second); //?
  areAnagrams(first, third); //?
  mostRepeatedChar(str); //?
  capitalizeFirstLetters(str); //?
  isPalindrome(palindrome); //?
  