/**
* Return a list of all possible third side lengths (integers) without right
* trangles.
*
* @param sideA Integer
* @param sideB Integer
*
* @throws {TypeError} If either sideA or sideB is not an integer.
*
* @example
* sideLen(1, 1) → [1]
* sideLen(3, 4) → [2, 3, 4, 6] // 5 is removed as it's a right triangle
* sideLen(4, 6) → [3, 4, 5, 6, 7, 8, 9]
*/functionsideLen(sideA:number,sideB:number):number[]{if(!Number.isInteger(sideA)||!Number.isInteger(sideB)){thrownewTypeError('Both provided parameters must be integers');}constmin=Math.abs(sideA-sideB);constmax=sideA+sideB;consthypot=Math.hypot(sideA,sideB);constlengths:number[]=[];for(leti=min+1;i<max;i++){if(i!==hypot){lengths.push(i);}}returnlengths;}
I think this is the first time I see someone do runtime type checking in TypeScript. Plus, your code helped me understand the goal of the challenge of today. Thanks for that!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
TypeScript
I think this is the first time I see someone do runtime type checking in TypeScript. Plus, your code helped me understand the goal of the challenge of today. Thanks for that!