1713609234

Coding challenges to help improve your programming logic skills.


Here's a list of challenges to improve our programming practices. 1. **Recursive Factorial**: Write a recursive function to calculate the factorial of a number. 2. **Array Sum**: Write a function to calculate the sum of all the elements in an array. 3. **Palindrome Check**: Write a function to check if a string is a palindrome. 4. **List Sorting**: Implement a sorting algorithm (such as bubble sort, selection sort, or merge sort) to sort a list of numbers. 5. Fibonacci: Write a function to calculate the nth term of the Fibonacci sequence. 6. **Word Count**: Write a function to count the number of 7. words in a string. 7. **Temperature Conversion**: Write functions to convert between Celsius, Fahrenheit and Kelvin. 8. **Longest Growing Subsequence**: Write a function to find the longest growing subsequence in a list of numbers. 9. **Mean and Median**: Write functions to calculate the mean and median of a list of numbers. 10. **Anagram Check**: Write a function to check if two strings are anagrams of each other. Leave a solution for one of them in the comments. Because I'm left with the task of solving this one: ## Recursive Factorial ```js function recursiveFactorial(n) { // Base case: factorial of 0 or 1 is 1 if (n === 0 || n === 1) { return 1; } // Recursive case: factorial of n is n times factorial of (n-1) else { return n * recursiveFactorial(n - 1); } } // Example usage: let number = 5; let result = recursiveFactorial(number); console.log(`The factorial of ${number} is ${result}`); ```

(2) Comments
amargo85
amargo85
0

[Deleted]


fschmidt
fschmidt
0

You don't need to check if n===1, so I would leave that out. <br> The performance here depends on whether Javascript has tail call optimization, and I don't know if it does.


Welcome to Chat-to.dev, a space for both novice and experienced programmers to chat about programming and share code in their posts.

About | Privacy | Terms | Donate
[2024 © Chat-to.dev]