simple-math-operations-lush
v1.0.2
Published
   ;
// Addition
console.log(mathOps.add(5, 3)); // Output: 8
// Subtraction
console.log(mathOps.subtract(5, 3)); // Output: 2
// Multiplication
console.log(mathOps.multiply(5, 3)); // Output: 15
// Division
console.log(mathOps.divide(5, 3)); // Output: 1.666...
console.log(mathOps.divide(5, 0)); // Output: Cannot divide by zeroAPI Documentation
add(a, b)
- Description: Adds two numbers
aandb. - Parameters:
a(Number): The first number.b(Number): The second number.
- Returns: The sum of
aandb.
subtract(a, b)
- Description: Subtracts
bfroma. - Parameters:
a(Number): The first number.b(Number): The second number.
- Returns: The difference between
aandb.
multiply(a, b)
- Description: Multiplies two numbers
aandb. - Parameters:
a(Number): The first number.b(Number): The second number.
- Returns: The product of
aandb.
divide(a, b)
- Description: Divides
abyb. - Parameters:
a(Number): The numerator.b(Number): The denominator.
- Returns: The quotient of
adivided byb. - Note: If
bis0, it returns"Cannot divide by zero".
Examples
Basic Usage
Here’s a simple example demonstrating how to use the module:
const mathOps = require('simple-math-operations');
const num1 = 10;
const num2 = 5;
console.log(`Addition: ${mathOps.add(num1, num2)}`); // Output: 15
console.log(`Subtraction: ${mathOps.subtract(num1, num2)}`); // Output: 5
console.log(`Multiplication: ${mathOps.multiply(num1, num2)}`); // Output: 50
console.log(`Division: ${mathOps.divide(num1, num2)}`); // Output: 2Chaining Operations
You can chain multiple operations together for more complex calculations:
const mathOps = require('simple-math-operations');
const result = mathOps.add(
mathOps.multiply(2, 3),
mathOps.divide(10, 2)
);
console.log(`Result: ${result}`); // Output: 11Error Handling
The divide function handles division by zero gracefully:
const mathOps = require('simple-math-operations');
const result = mathOps.divide(10, 0);
console.log(result); // Output: Cannot divide by zeroContributing
Contributions are welcome! If you’d like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Make your changes and write tests if applicable.
- Submit a pull request.
For major changes, please open an issue first to discuss what you’d like to change.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Support
If you find this module useful, please consider giving it a ⭐️ on GitHub or supporting the author.
Author
👤 Your Name
- GitHub: @lakshay-goyal
- Email: [email protected]
