본문 바로가기

Algorithms

(17)
freeCodeCamp - 7. Repeat a String Repeat a String [Basic Algorithm Scripting] Repeat a String Repeat a String https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/repeat-a-string-repeat-a-string www.freecodecamp.org function repeatStringNumTimes(str, num) { let answer = "" if(num
freeCodeCamp - 6. Confirm the Ending [Basic Algorithm Scripting] Confirm the Ending https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/confirm-the-ending www.freecodecamp.org function confirmEnding(str, target) { if(str.slice(-target.length, str.length) == target) return true return false; } confirmEnding("Bastian", "n");
freeCodeCamp - 5. Return Largest Numbers in Arrays [Basic Algorithm Scripting] Return Largest Numbers in Arrays https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/return-largest-numbers-in-arrays www.freecodecamp.org function largestOfFour(arr) { let myArr = [] for (let a of arr){ console.log(a) myArr.push(Math.max.apply(null, a)) } return myArr; } largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 10..
freeCodeCamp - 4. Find the Longest Word in a String [Basic Algorithm Scripting] Find the Longest Word in a String https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/find-the-longest-word-in-a-string www.freecodecamp.org so1) function findLongestWordLength(str) { let arr = str.split(' ') let arr2 = [] for(let a of arr){ arr2.push(a.length) } return Math.max(...arr2) } findLongestWordLength("The quick brown fox jumped over t..
freeCodeCamp - 3. Factorialize a Number [Basic Algorithm Scripting] Factorialize a Number https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/factorialize-a-number www.freecodecamp.org function factorialize(num) { let sum = 1 if(num > 0) { for(let i=1; i
freeCodeCamp - 2. Reverse a String [Basic Algorithm Scripting] Reverse a String https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/reverse-a-string www.freecodecamp.org function reverseString(str) { str = str.split('').reverse().join('') return str; } reverseString("hello");
freeCodeCamp - 1. Convert Celsius to Fahrenheit [Basic Algorithm Scripting] Convert Celsius to Fahrenheit function convertCtoF(celsius) { let fahrenheit; fahrenheit = celsius * 9/5 + 32 return fahrenheit; } convertCtoF(30); https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures www.freecodecamp.org