W
William James
John said:Xah said:In lisp, python, perl, etc, you'll have 10 or so lines. In C or
Java, you'll have 50 or hundreds lines.
Java:
static float[] normal(final float[] x) {
float sum = 0.0f;
for (int i = 0; i < x.length; ++i) sum += x * x;
final float divisor = (float) Math.sqrt(sum);
float[] a = new float[x.length];
for (int i = 0; i < x.length; ++i) a = x/divisor;
return a;
}
"We don't need no stinkin' loops!"
SpiderMonkey Javascript:
function normal( ary )
{ div=Math.sqrt(ary.map(function(x) x*x).reduce(function(a,b) a+b))
return ary.map(function(x) x/div)
}