Manafall Daily Quest

Prime Factorization

Function Name: calculatePrimeFactors

Description

Write a function `calculatePrimeFactors` that receives a single positive integer greater than 1 and returns an array of its prime factors.

Prime factors are the prime numbers that multiply together to equal the given integer. Every number greater than 1 is either a prime itself or can be made by multiplying prime numbers together.

The returned array should contain the prime factors sorted in ascending order. If the input number is prime, return an array with just that number as the only element.

Requirements

  • The function `calculatePrimeFactors` must take exactly one argument: a positive integer greater than 1.
  • The function must return an array of numbers, which represent the prime factors of the input integer.
  • The array should have the prime factors in ascending order.
  • You must not use any third-party libraries or plugins.
  • Consider optimizing the function for the efficient calculation of prime factors to handle large integers.

Examples

// Example 1: Prime factorization of 18let factorsOfEighteen = calculatePrimeFactors(18);console.log(factorsOfEighteen); // Output should be [2, 3, 3]// Example 2: Prime factorization of a prime numberlet factorsOfTwentyThree = calculatePrimeFactors(23);console.log(factorsOfTwentyThree); // Output should be [23]

Links

https://en.wikipedia.org/wiki/Prime_numberhttps://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetichttps://en.wikipedia.org/wiki/Prime_factor

Balanced Parentheses

Sat Oct 26 2024

Write a function that takes a string containing only parentheses '()', '[]', and '{}' characters. The function must check whether the parentheses in the string are correctly balanced. Every opening parenthesis must have a corresponding closing parenthesis of the same type, and parentheses must close in the correct order. Your function should return true if the string is balanced, otherwise, return false.

Prev Quest

String Permutation Rank

Mon Oct 28 2024

Write a function that calculates the rank of a string permutation in lexicographically sorted order without actually generating all permutations. For example, in the sorted list of permutations of 'abc', the rank of 'abc' is 1, 'acb' is 2, and so on. The function should handle duplicates and handle upper and lowercase characters as different. You must not use external libraries or built-in permutation functions. The rank should start at 1.

Next Quest