* Create a function that takes in the length of two sides of a
triangle and returns an array of all integers that could be the
length of the third side.
* Note: The sum of two sides of a triangle is always greater than
the third.
*/
exports.default = (firstSide, secondSide) => {
// Your code goes here.
};
const triangleSideRanges = require('./question').default;
console.log(triangleSideRanges(3, 4)); // Expected Output:[ 2, 3, 4, 5, 6 ]
console.log(triangleSideRanges(11, 7)); // Expected Output:[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
console.log(triangleSideRanges(5, 18)); // Expected Output:[14, 15, 16, 17, 18, 19, 20, 21, 22]
console.log(triangleSideRanges(23, 4)); // Expected Output:[20, 21, 22, 23, 24, 25, 26]
URGENT PLEASE HELP!
Solution:
var ans = [];
var diff;
if(firstSide > secondSide) {
diff = firstSide-secondSide;
}
else {
diff = secondSide-firstSide;
}
var i;
for(i=diff+1;i<(firstSide+secondSide);i++) {
ans.push(i);
}
return ans;
According to your question requirements javascript for fuction that takes in the lengths of two sides of triangle and return array of all integers that could be the length of third side.
Get Answers For Free
Most questions answered within 1 hours.