Manafall Daily Quest

Custom Sort String

Function Name: sortCharactersByOrder

Description

You need to write a function, sortCharactersByOrder, which takes in two strings as parameters.

The first string, 'order', represents the order of characters defined by the user.

The second string, 'text', contains the text that needs to be sorted according to the order provided by the 'order' string.

The function should return a new string in which the characters of 'text' are ordered based on the sequence of characters present in the 'order'.

Characters in 'text' which are not present in 'order' should be appended to the end of the returned string, in the original order they appear in 'text'.

If the 'order' string has characters not present in 'text', they should be ignored.

The function should be case-sensitive, treating upper and lower case letters as different characters.

Requirements

  • The function must be case-sensitive.
  • If 'order' or 'text' are empty strings, the function should return 'text' unchanged.
  • Assume that 'order' may contain duplicated characters, but they should be treated as a single occurrence in the ordering process.
  • The function should not use any built-in language features that inherently perform the whole sorting task, the focus should be on algorithm development.

Examples

Given the 'order'='cba' and 'text'='abcd', the function should return 'cbad'.If 'order'='ghj' and 'text'='hello', since none of the characters in 'hello' occur in 'order', the function should return 'hello' unchanged.If 'order'='xy' and 'text'='xxyyxxzz', the function should return 'xxyyxxzz'.

File Path Simplifier

Wed Aug 14 2024

Write a function that simplifies an input string representing a file path.For simplification, the function should follow these rules:1. A double period '..' moves the directory up a level, while a single period '.' means the current directory and should be removed.2. The return value should always begin with a slash '/', and there should be only one slash '/' separating each directory name. The last directory name (if it exists) should not end with a slash unless the path is just a root '/'.3. The function should eliminate any multiple slashes '//' and return a canonical path.4. Assume all input paths are non-empty strings.

Prev Quest

Area of Polygon

Fri Aug 16 2024

In this challenge, you're required to write a function named `calculatePolygonArea` that calculates the area of a simple polygon. The polygon is defined by its vertices in a 2D plane. The vertices are provided in the form of an array of points, each point being an array with two integers representing the x and y coordinates. It is guaranteed that the vertices are listed in order, either clockwise or counter-clockwise, and the polygon is non-self-intersecting.

Next Quest