JavaScript hypot
Returns sqrt(num1*num1 + num2*num2)
1 2 3 4 56 7 8 9 1011 12 | function hypot (x, y) { // Returns sqrt(num1*num1 + num2*num2) // // version: 909.322 // discuss at: http://phpjs.org/functions/hypot // + original by: Onno Marsman // * example 1: hypot(3, 4); // * returns 1: 5 // * example 2: hypot([], 'a'); // * returns 2: 0 return Math.sqrt(x*x + y*y) || 0; } |
Examples
» Example 1
Running
1 | hypot(3, 4); |
Should return
1 | 5 |
» Example 2
Running
1 | hypot([], 'a'); |
Should return
1 |
Dependencies
No dependencies, you can use this function standalone.
Open syntax issues
php.js uses JsLint to help us keep our code consistent and prevent some common bugs.
Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.
Authors
Thanks to the following developers, you get to have hypot goodness in JavaScript.
No comments yet. Be the first!
spread the word:
Use any PHP function in JavaScript
These kind folks have already donated: Anonymous and Shawn Houser.
<your name here>