CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-mathjs

Math.js is an extensive math library for JavaScript and Node.js featuring a flexible expression parser, symbolic computation, and support for numbers, big numbers, complex numbers, fractions, units, and matrices.

84

1.47x
Overview
Eval results
Files

task.mdevals/scenario-1/

Unit Converter Utility

Build a utility that converts between different units of measurement and finds the best unit representation for values.

Capabilities

Convert between specific units

  • Converting 1000 meters to kilometers returns a value with 1 km @test
  • Converting 60 minutes to hours returns a value with 1 hour @test
  • Converting 1024 bytes to kilobytes returns a value with 1 KiB @test

Find optimal unit representation

  • Given 5000 meters, finding the best unit returns a value in kilometers @test
  • Given 3600 seconds, finding the best unit returns a value in hours @test
  • Given 1048576 bytes, finding the best unit returns a value in MiB @test

Implementation

@generates

API

/**
 * Converts a value from one unit to another.
 *
 * @param {number|string} value - The value with original unit (e.g., "1000 m")
 * @param {string} targetUnit - The target unit to convert to (e.g., "km")
 * @returns {number|string} The converted value with the target unit
 */
function convertUnit(value, targetUnit) {
  // IMPLEMENTATION HERE
}

/**
 * Converts a value to the best fitting unit with appropriate prefix.
 *
 * @param {number|string} value - The value with original unit (e.g., "5000 m")
 * @returns {number|string} The value in the most appropriate unit
 */
function toBestUnit(value) {
  // IMPLEMENTATION HERE
}

module.exports = {
  convertUnit,
  toBestUnit
};

Dependencies { .dependencies }

mathjs { .dependency }

Provides unit conversion and mathematical operations support.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-mathjs

tile.json