- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Isosceles triangles with nearest perimeter using JavaScriptn
Almost Isosceles Triangle
An Almost Isosceles Integer Triangle is a triangle that all its side lengths are integers and also, two sides are almost equal, being their absolute difference 1 unit of length.
Problem
We are required to write a JavaScript function that takes in a number which specifies the perimeter of a triangle.
Our function should find the measurement of such an almost isosceles triangle whose perimeter is nearest to the input perimeter.
For example, if the desired perimeter is 500,
Then the almost isosceles triangle with the nearest perimeter will be − [105, 104, 181]
Example
Following is the code −
const perimeter = 500; const almostIsosceles = (perimeter = 0) => { let a = perimeter; for(; a > 0; a--){ for(let b = perimeter; b > 0; b--){ for(let c = perimeter; c > 0; c--){ if(a + b + c > perimeter || a !== b + 1 || (Math.pow(a, 3) - Math.pow(b, 3) !== Math.pow(c, 2))){ continue; }; return [a, b, c]; }; }; }; return []; }; console.log(almostIsosceles(perimeter));
Output
[ 105, 104, 181 ]
- Related Articles
- Isosceles triangles with nearest perimeter using JavaScript
- All right triangles with specified perimeter in JavaScript
- How to round up to the nearest N in JavaScript
- Count number of right triangles possible with a given perimeter in C++
- Find the Number of Triangles After N Moves using C++
- Count of triangles with total n points with m collinear in C++
- Fill in the blanks by using the correct word given in brackets.All …………….. triangles are similar. (isosceles/equilateral)
- Find number of unique triangles among given N triangles in C++
- Forming the nearest time using current time in JavaScript
- Fill in the blanks using the correct word given in brackets: (iii) All ____________ triangles are similar. (isosceles, equilaterals)
- Nearest palindrome in JavaScript
- Picking the triangle edges with maximum perimeter JavaScript
- Nearest prime less than given number n C++
- Finding nearest Gapful number in JavaScript
- Nearest Prime to a number - JavaScript
- Replace All Consonants with Nearest Vowels In a String using C++ program

Advertisements