- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Volume difference of cuboids in JavaScript
Problem
We are required to write a JavaScript function that takes in two arrays, specifying the lengths, widths, and heights of two cuboids.
Our function should calculate the volume of both cuboids and return their absolute difference.
Example
Following is the code −
const h1 = 10; const w1 = 12; const l1 = 15; const h2 = 12; const w2 = 15; const l2 = 9; const findVolumeDifference = (l1, w1, h1, l2, w2, h2) => { const v1 = l1 * w1 * h1; const v2 = l2 * w2 * h2; const diff = Math.abs(v1 - v2); return diff; }; console.log(findVolumeDifference(l1, w1, h1, l2, w2, h2));
Output
180
Advertisements