Manafall Daily Quest

Frequency Sort

Function Name: frequencySort

Description

Write a function named 'frequencySort' that sorts an array based on the frequency of the elements. If two elements have the same frequency, then the smaller number comes first.

The function will take one parameter, an array of integers, and should return a new array of integers sorted based on the aforementioned criteria.

Requirements

  • The function must sort the elements in descending order based on their frequency of occurrence.
  • If two elements have the same frequency, sort them in ascending numerical order.
  • The original array should not be modified.
  • Use only built-in language constructs and data structures; no third-party libraries or frameworks.
  • Optimize for readability and clean coding practices.

Examples

Given the array [3, 3, 2, 1, 2, 4, 4, 4, 4], the function should return [4, 4, 4, 4, 3, 3, 2, 2, 1].Given the array [5, 7, 5, 2, 5, 2], the function should return [5, 5, 5, 2, 2, 7].Given the array [1, 2, 3, 4], the function should return [1, 2, 3, 4].

Sum of Multiples

Wed Dec 11 2024

In this challenge, you are required to implement a function that calculates the sum of all multiples of a set of numbers up to a certain limit. For example, if the set is [3, 5] and the limit is 10, the function should return the sum of the numbers that are multiples of either 3 or 5 below the limit: 3, 5, 6, and 9, which adds up to 23.

Prev Quest

Merge Intervals

Fri Dec 13 2024

Write a function 'mergeIntervals' that takes an array of intervals where each interval is represented as an array of two integers, and the intervals are sorted in ascending order based on the start of each interval. The function should merge all overlapping intervals and return an array of the resulting non-overlapping intervals sorted in ascending order.

Next Quest