$$
{\color{red}Algorithm \space 🔱 \space \color{lightgreen}Challenge}
$$
$$
{\color{red}Made \space \color{red} With \space \color{red}❤️ }
$$
A very good place to practice algorithms is LeetCode - this exercise contains practice challenges similar to the problems found on LeetCode.


Table of Contents 🏽 🏼 🏻 🏿 🏾
Introduction
This repository contains a collection of algorithm challenges designed to help you improve your JavaScript skills. Each challenge includes a brief description and an example to illustrate the expected output. Whether you are a beginner or an experienced developer, these challenges will help you practice and enhance your problem-solving abilities.
Installation
To set up the project locally, follow these steps:
-
Clone the repository:
git clone https://github.com/your-username/algorithm-challenges.git
Challenge 1: Reverse a String 
reverseString("hello") === "olleh";
Explanation: This challenge requires you to write a function that takes a string as input and returns the string in reverse order. For example, if the input is “hello”, the output should be “olleh”.
Challenge 2: Validate a Palindrome 
isPalindrome("racecar") === true;
isPalindrome("hello") === false;
Explanation: A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). This challenge requires you to write a function that checks if a given string is a palindrome.
Challenge 3: Reverse an Integer 
reverseInt(521) === 125;
Explanation: This challenge requires you to write a function that takes an integer as input and returns the integer with its digits reversed. For example, if the input is 521, the output should be 125.
Challenge 4: Capitalize Letters 
capitalizeLetters("i love javascript") === "I Love Javascript";
Explanation: This challenge requires you to write a function that takes a string as input and returns the string with the first letter of each word capitalized. For example, if the input is “i love javascript”, the output should be “I Love Javascript”.
Challenge 5: Max Character 
maxCharacter("javascript") === "a";
Explanation: This challenge requires you to write a function that takes a string as input and returns the character that appears most frequently in the string. For example, if the input is “javascript”, the output should be “a”.
Challenge 6: FizzBuzz 
Explanation: FizzBuzz is a classic programming challenge that requires you to write a program that prints the numbers from 1 to 100. However, for multiples of 3, you should print “Fizz” instead of the number, for multiples of 5, you should print “Buzz”, and for multiples of both 3 and 5, you should print “FizzBuzz”.
Challenge 7: Longest Word 
longestWord("Hi there, my name is Brad") === "there,";
longestWord("My name is Brad") === ["name", "brad"];
longestWord("Brad") === "brad";
Explanation: This challenge requires you to write a function that takes a string as input and returns the longest word in the string. If there are multiple words with the same length, you can return an array of those words.
Challenge 8: Array Chunking 
chunkArray([1, 2, 3, 4, 5, 6, 7], 3) === [[1, 2, 3], [4, 5, 6], [7]];
chunkArray([1, 2, 3, 4, 5, 6, 7], 2) === [[1, 2], [3, 4], [5, 6], [7]];
Explanation: This challenge requires you to write a function that takes an array and a chunk size as input and splits the array into smaller arrays (chunks) of the specified size. For example, if the input array is [1, 2, 3, 4, 5, 6, 7] and the chunk size is 3, the output should be [[1, 2, 3], [4, 5, 6], [7]].
Challenge 9: Flatten Array 
[[1, 2], [3, 4], [5, 6], [7]] === [1, 2, 3, 4, 5, 6, 7];
Explanation: This challenge requires you to write a function that takes an array of arrays as input and flattens it into a single array. For example, if the input is [[1, 2], [3, 4], [5, 6], [7]], the output should be [1, 2, 3, 4, 5, 6, 7].
Challenge 10: Anagram 
"anagram" === "nagaram";
"Dormitory" === "dirty room##";
Explanation: An anagram is a word or phrase formed by rearranging the letters of another word or phrase. This challenge requires you to write a function that takes two strings as input and returns true if they are anagrams of each other, and false otherwise.
Challenge 11: Add All Numbers 
addAll(2, 5, 6, 7) === 20;
Explanation: This challenge requires you to write a function that takes any number of arguments and returns their sum. For example, if the input is 2, 5, 6, 7, the output should be 20.
Challenge 12: Sum All Primes 
sumAllPrimes(10) === 17;
Explanation: A prime number is a whole number greater than 1 whose only factors are 1 and itself. This challenge requires you to write a function that takes a number as input and returns the sum of all prime numbers up to that number. For example, if the input is 10, the output should be 17 (2 + 3 + 5 + 7).
Challenge 13: Seek and Destroy 
seekAndDestroy([2, 3, 4, 6, 6, "hello"], 2, 6) === [3, 4, "hello"];
Explanation: This challenge requires you to write a function that takes an array and additional arguments, and removes all elements from the array that match any of the additional arguments. For example, if the input is [2, 3, 4, 6, 6, “hello”], 2, 6, the output should be [3, 4, “hello”].
Challenge 14: Even & Odd Sums 
evenOddSums([50, 60, 60, 45, 71]) === [170, 116];
Explanation: This challenge requires you to write a function that takes an array as input and returns an array with two elements: the sum of all even numbers and the sum of all odd numbers. For example, if the input is [50, 60, 60, 45, 71], the output should be [170, 116].
$$
$$
评论