Area of Polygon
Function Name: calculatePolygonArea
Description
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.
Requirements
- The function `calculatePolygonArea` must take one parameter: an array of points.
- Each point in the array is an array with two integers [x, y].
- The function should return the area of the polygon as a floating-point number.
- Do not assume the polygon is regular. It can be any simple (non-self-intersecting) shape.
- The area should be positive regardless of the order of vertices (clockwise or counter-clockwise).
- You may not use any libraries or built-in functions that directly calculate the area of polygons.
- Implement the Shoelace formula to solve this problem.
Examples
If the input is `[[0, 0], [4, 0], [4, 4], [0, 4]]` (a square), the function should return `16`.If the input is `[[1, 1], [3, 4], [6, 1]]` (a triangle), the function should return `7.5`.
Links
Custom Sort String
Thu Aug 15 2024
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.
Route Planner
Sat Aug 17 2024
Write a function `findShortestPath` that takes a two-dimensional grid of possible paths and finds the shortest path from the top-left corner to the bottom-right corner. The grid is represented by a 2D array where each element can be 1 (path) or 0 (obstacle). You are only allowed to move right or down. If there is no path to the destination, the function should return null. The function should return the path as a list of coordinates.