Here are my solutions for the first three algorithms:
Convert Celsius to Fahrenheit
function convertToF(celsius) {
return (celsius * (9/5)) + 32;
}
Reverse a String
I came up with the following, which splits the string into an array of letters and then adds the letters to a new string using the map() function.
function reverseString(str) {
let newStr = "";
return str.split('').map(letter => newStr = letter + newStr)[newStr.length-1];
}
However, after looking through the freeCodeCamp Algorithm Challenge Guide: Reverse a String topic, I realized that I overcomplicated this and should’ve looked to built-in functions instead:
function reverseString(str) {
return str.split('').reverse().join('');
}
Factorialize a Number
I started with the following, using a for loop to loop through the range between num and one and then multiply the counter by the current result:
function factorialize(num) {
let result = 1;
for (let numIndex=num; numIndex > 0; numIndex--) {
result *= numIndex;
}
return result;
}
However, after looking at the freeCodeCamp Algorithm Challenge Guide: Factorialize A Number topic, and watching the video on recursion listed in the guide and this part of another video on recursion, I came up with this, which is more difficult to understand, but cleaner overall:
function factorialize(num) {
if (num === 0) return 1;
return num * factorialize(num-1);
}
The following is another version shared by @Kagerjay (freeCodeCamp Algorithm Challenge Guide: Factorialize A Number) that I like the best, once I wrap my head around recursion:
function factorialize(num) {
return num === 0 ? 1 : num * factorialize(num-1);
}
This Recursion and Recursive Functions video does a great job of explaining how the above recursive factorialize function works.
Any thoughts on the above solutions? Did anyone do anything different or find helpful resources to learn more about these? 