coding_test.ts

Home   »   coding_test.ts

const s = "Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You’ve solved the wrong problem. Work hard to improve"
function sumOfSentence(input: string){
  const vowels = new Set(['a','e','i','o','u'])
  let sum = 0;
  for(let i=0; i= 65 && asciiValue <= 90 || asciiValue >= 97 && asciiValue <= 122){
      if(vowels.has(character.toLowerCase())){
        sum -= asciiValue;
      }else{
        sum += asciiValue
      }
    }
  }
  return sum;
}
                                                                                     
console.log(sumOfSentence(s))                                                                                 


function sumOfAllOddNumbersInFibonacciLessThan(threshold: number){
  let first = 0;
  let second = 1;
  let next = 0;
  let sum = first + second;
  while(next < threshold){
    if(next % 2 !== 0){
      sum += next;
    }
    next = first + second;
    first = second;
    second = next;
    console.log(next)
  }
  return sum;
}

console.log(sumOfAllOddNumbersInFibonacciLessThan(13))
    
function getXCount(num: number){
  let integerToRomanMap = new Map([
    [90, "XC"], [80, "LXXX"], [70, "LXX"], [60, "LX"], 
    [50, "L"], [40, "XL"], [30, "XXX"], [20, "XX"], 
    [10, "X"], [9, "IX"], [8, "VIII"], [7, "VII"], [6, "VI"], 
    [5, "V"], [4, "IV"], [3, "III"], [2, "II"], [1, "I"]
  ])
  let countX = 0;
  for(let i=10; i<=num; i++){
    let num = i%100;
    while(num > 0){
      let len = String(num).length;
      let divisor = Math.pow(10, len - 1)
      let quotient = Math.floor(num/divisor)
      num = num % divisor
      if(integerToRomanMap.has(divisor * quotient)){
        let value =  integerToRomanMap.get(divisor * quotient)
        countX += getCount(value)
      }else{
        while(quotient > 0){
          let value = integerToRomanMap.get(divisor)
          quotient--;
          countX += getCount(value)
        }
      }
    }
  }
  return countX;
}

function getCount(value: string){
  let countX = 0;
  for(let j=0; j

Leave a Reply

Your email address will not be published. Required fields are marked *