Manafall Daily Quest

Temperature Converter

Function Name: convertTemperature

Description

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.

Requirements

  • The function must take exactly two parameters: the value (number) and the unit (string).
  • The unit parameter will only be one of the following: 'C', 'F', or 'K'.
  • The function must return an object with keys 'C', 'F', and 'K'.
  • The function should not use any third-party libraries or modules.
  • Avoid hard-coded constants, and use proper formulas for conversion.
  • Handle incorrect inputs by returning an error message or null.

Examples

convertTemperature(0, 'C') should return {C: 0, F: 32, K: 273.15}.convertTemperature(32, 'F') should return {C: 0, K: 273.15, F: 32}.convertTemperature(273.15, 'K') should return {C: 0, F: 32, K: 273.15}.

Links

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

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.

Prev Quest

LinkedListCycleDetector

Tue Nov 05 2024

Write a function named 'hasCycle' that takes the head of a singly linked list as its single parameter.The function should determine whether the linked list contains a cycle, which is a situation where nodes in the list form a loop.A singly linked list is said to have a cycle if, by continuously following the next pointers, a node is encountered that has already been visited.The function should return a boolean value: true if the list contains a cycle, and false otherwise.

Next Quest