Manafall Daily Quest

Customized Caesar Cipher

Function Name: caesarCipherEncrypt

Description

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'.

Requirements

  • The `caesarCipherEncrypt` function must take exactly two parameters: a string `text` and an integer `shift`.
  • The function should maintain the case of the original letters (e.g., uppercase letters remain uppercase).
  • Non-letter characters should not be changed and should remain in their original position in the string.
  • The function should be able to support both positive and negative shifts, wrapping around the alphabet accordingly.

Examples

`caesarCipherEncrypt('Hello, World!', 3)` should return `'Khoor, Zruog!'`.`caesarCipherEncrypt('abc', -3)` should return `'xyz'`.`caesarCipherEncrypt('The Quick Brown Fox!', 10)` should return `'Dro Aesmu Lbygx Pyh!'`.

Links

https://en.wikipedia.org/wiki/Caesar_cipher

Subarray Sum Equals K

Fri Nov 01 2024

Write a function 'subarraySum' that takes an array of integers (nums) and an integer (k), and returns the number of continuous subarrays whose sum equals to k.You may assume that the array and the target integer k will have at least one element.Note that the array can contain both positive and negative integers.

Prev Quest

Pathfinding in Grid

Sun Nov 03 2024

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.

Next Quest