Ad
Algebra
Mathematics
Algorithms
Logic
Code
Diff
  • function multiply(a, b){
        a = String(a).split('').reverse()
        b = String(b).split('').reverse()
        
        partial_sums = []
        a.forEach((value, index)=>{
          let r = b.map(othervalue=>{return value*othervalue})
          partial_sums.push(Array(index).fill(0).concat(r))
        })
        
        result = Array(a.length + b.length - 1).fill(0)
        partial_sums.forEach(sum=>{
          sum.forEach((digit,index)=>{
            result[index] = result[index] + digit
          })
        })
        return result.reverse()
    }
    • def multiply(a, b):
    • #your code
    • pass
    • function multiply(a, b){
    • a = String(a).split('').reverse()
    • b = String(b).split('').reverse()
    • partial_sums = []
    • a.forEach((value, index)=>{
    • let r = b.map(othervalue=>{return value*othervalue})
    • partial_sums.push(Array(index).fill(0).concat(r))
    • })
    • result = Array(a.length + b.length - 1).fill(0)
    • partial_sums.forEach(sum=>{
    • sum.forEach((digit,index)=>{
    • result[index] = result[index] + digit
    • })
    • })
    • return result.reverse()
    • }