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<0) return answer
  else {
    for(let i = 0; i<num; i++){
      answer = answer + str
    }
  return answer
  }
}

repeatStringNumTimes("abc", 3);

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");

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, 1001, 857, 1]]);

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 the lazy dog");

 

sol2)

function findLongestWordLength(str) {
  let arr = str.split(' ')
  let max = 0
  for (let a of arr){
    if(a.length >= max){
      max = a.length
    }
  }
  return max
  return str.length;
}

findLongestWordLength("The quick brown fox jumped over the lazy dog");

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<num+1; i++){
      sum = sum*i
    }
  }
  return sum;
}

factorialize(5);

 

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");

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

 

+ Recent posts