Return Exponents of Prime Factors

Published by persolut in

You are given an array of prime factors arr and a target. When each number in the array is raised to an appropriate power their product will be equal to the target.

Your role is to return the exponents. All these arrays will have a length of three. Basically, it is three numbers whose product is equal to challenge. The only difference is what you are expected to return.

Examples

productEqualTarget([2, 3, 5], 600) ➞ [3, 1, 2]
// Because 2^3*3^1*5^2 = 600

productEqualTarget([2, 3, 5], 720) ➞ [4, 2, 1]
// Because 2^4*3^2*5^1 = 720

Notes

  • The exponents you will return are expected to replace the base in the array.
  • Your returned values must be in the same order as the bases.
Watch a quick demo on how Edabit works.