Pathfinding in Grid
Function Name: findPath
Description
Write a function 'findPath' that finds a path from the top-left corner to the bottom-right corner of a 2D grid. The function should take two parameters: a 2D array representing the grid and a boolean function 'canPass' that takes a grid cell's value and returns true if the cell is passable, false otherwise.
The grid will be represented as a 2D array of integers, where 0 means an empty cell that can be passed and any other number means an obstacle that cannot be passed. The path must either move right or down at each step.
The function should return an array of coordinates that represent the path. Each coordinate is an array with two elements representing the row and column indices in the grid. If no path exists, the function should return null.
Requirements
- Do not use any third-party libraries or modules.
- The path does not need to be the shortest path, but it must reach the end if a path exists.
- Optimize the function to handle large grids efficiently.
- Document the time complexity of your solution.
Examples
Given a grid: [[0, 1, 0], [0, 0, 0], [1, 0, 0]], and 'canPass' function: (cell) => cell === 0;Calling findPath(grid, canPass) should return [[0, 0], [1, 0], [1, 1], [1, 2], [2, 2]].If the grid was: [[0, 1], [1, 0]], there is no valid path, and the function should return null.
Links
Customized Caesar Cipher
Sat Nov 02 2024
The goal of this challenge is to implement a customized version of the Caesar Cipher, a classic encryption technique. The function should take a string and an integer as parameters, and return a new string where each letter is shifted by the specified number of places down the alphabet. Additionally, this customized cipher should leave non-letter characters unchanged and should maintain the casing of the characters.Your task is to write the function `caesarCipherEncrypt(text, shift)` where `text` is the string to be encrypted and `shift` is the number of places each letter must be shifted. The shift can be a positive or negative integer, meaning the letters can be shifted to the right or left respectively. Implement the function to wrap around, such that shifting 'z' by 1 would result in 'a', and shifting 'a' by -1 would result in 'z'.
Temperature Converter
Mon Nov 04 2024
Write a function that converts temperatures between different units.The function will take two parameters: the value to convert (a floating-point number) and the unit it's converting from ('C', 'F', or 'K' representing Celsius, Fahrenheit, and Kelvin, respectively).The function should return an object with the keys 'C', 'F', and 'K', representing the value of the temperature in Celsius, Fahrenheit, and Kelvin.Conversions should be accurate to at least one decimal place.