Answers for "common Denominators in an array js"

0

common Denominators in an array js

function convertFrac(lst){
  
  let numerator = [];
  let denominator = [];
  let allDen;
  let str = '';

  lst.forEach((e,i,arr)=>{
    numerator.push(arr[i][0]);
    denominator.push(arr[i][1])
  })

  for (let i = 1; i < 1000000; i++) {
    all = denominator.every(e => i % e == 0)
    if (all) {
      allDen = i;
      break;
    }
  }
  
  numerator.forEach((e,i)=>str +=`(${(allDen/denominator[i])},${allDen})`)
  return str;
}
Posted by: Guest on October-14-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language