File Path Simplification
Function Name: simplifyPath
Description
Implement a function that takes a string representing an absolute file path in a Unix-style file system, and returns the simplified canonical path. In a Unix-like operating system, a canonical path is the simplest absolute path that points to the same location as the original path.
A canonical path has the following properties:
- The path starts with a single slash ('/').
- Any two directories are separated by a single slash ('/').
- The path does not end with a trailing '/'.
- The path only contains the directories on the path from the root directory to the target file or directory, with the exception of '.' or '..' which are interpreted as current and parent directory respectively.
Requirements
- The input path will be a non-empty string of characters.
- The simplifyPath function should take a single string parameter representing the file path to simplify.
- The function should return the simplified canonical path as a string.
- The simplified path must not contain any '.' or '..' elements.
- Consecutive slashes ('//') should be reduced to a single slash ('/').
- If the path refers to the root directory, the return value should be '/'.
Examples
simplifyPath('/home/') returns '/home'simplifyPath('/../') returns '/'simplifyPath('/home//foo/') returns '/home/foo'simplifyPath('/a/./b/../../c/') returns '/c'simplifyPath('/a/../../b/../c//.//') returns '/c'
Links
Matrix Diagonal Summation
Sun Jul 28 2024
Write a function that accepts a two-dimensional square matrix (an array of arrays) and returns the absolute difference between the sums of its diagonals.For example, given a square matrix:[[1, 2, 3], [4, 5, 6], [7, 8, 9]]The left-to-right diagonal sums up to 1 + 5 + 9 = 15. The right-to-left diagonal sums up to 3 + 5 + 7 = 15. The function should return the absolute difference which is 0 in this case.
Simple Inventory Counter
Tue Jul 30 2024
Write a function `countInventory` that takes in a list of items sold in a store over the course of a day.The input list consists of strings, with each string representing an item name.The function should return a dictionary or map where each key-value pair represents the item and the number of times it was sold.The items should be accounted for in a case-insensitive manner.If the list is empty, return an empty dictionary or map.