Joe Astuccio

Joe Astuccio

FreeCodeCamp basic algorithms

09/14/20191 Min Read — In Gatsby, Security, FreeCodeCamp

My solutions to the FCC basic Algorithms

Convert Celsius to Fahrenheit

This is a simple math formula. You dont need the fahrenheit variable FCC h

1function convertToF(celsius) {
2 return (celsius * 9) / 5 + 32;
3}
1function sumAll(arr) {
2 const minNum = Math.min(...arr);
3 const maxNum = Math.max(...arr);
4 let sum = 0;
5
6 for (let i = minNum; i <= maxNum; i++) {
7 console.log(i);
8 sum += i;
9 }
10 return sum;
11}

other solutions:

1function range(start, end) {
2 return new Array(end - start + 1).fill(undefined).map((_, i) => i + start);
3}
4
5function range(start, end) {
6 if (start === end) return [start];
7 return [start, ...range(start + 1, end)];
8}