"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/es5-ext/math/hypot/shim.js" (8 Mar 2017, 899 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Thanks for hints: https://github.com/paulmillr/es6-shim
    2 
    3 'use strict';
    4 
    5 var some = Array.prototype.some, abs = Math.abs, sqrt = Math.sqrt
    6 
    7   , compare = function (a, b) { return b - a; }
    8   , divide = function (x) { return x / this; }
    9   , add = function (sum, number) { return sum + number * number; };
   10 
   11 module.exports = function (val1, val2/*, …valn*/) {
   12     var result, numbers;
   13     if (!arguments.length) return 0;
   14     some.call(arguments, function (val) {
   15         if (isNaN(val)) {
   16             result = NaN;
   17             return;
   18         }
   19         if (!isFinite(val)) {
   20             result = Infinity;
   21             return true;
   22         }
   23         if (result !== undefined) return;
   24         val = Number(val);
   25         if (val === 0) return;
   26         if (!numbers) numbers = [abs(val)];
   27         else numbers.push(abs(val));
   28     });
   29     if (result !== undefined) return result;
   30     if (!numbers) return 0;
   31 
   32     numbers.sort(compare);
   33     return numbers[0] * sqrt(numbers.map(divide, numbers[0]).reduce(add, 0));
   34 };