Instantly share code, notes, and snippets.

# arextar/LICENSE.txt forked from 140bytes/LICENSE.txt Created Sep 27, 2011

Summation function
 function( a, //Lower bound b, //Upper bound c, //[Step function] d, //Multiply e,f //Placeholders ){ c===true&&(d=c,c=0); //If c is true, use c as the 'multiply' param if(a==1&&!c&&!d) return (b*b+b)/2 //If it's a standard summation of 1..n, optimize for( e=!!d //initiate counter as d (will coerce to 0 if adding, 1 if multiplying) ;a<=b; //While lower bound is less than the upper bound... f=c?c(b):b, //If a step function is passed, use it d?e*=f:e+=f, //Perform the necessary operation b-- //Decrement the upper bound ); return e; //Return the result of the summation }
 function(a,b,c,d,e,f){c===!0&&(d=c,c=0);if(a==1&&!c&&!d)return(b*b+b)/2;for(e=!!d;a<=b;f=c?c(b):b,d?e*=f:e+=f,b--);return e}
 DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2011 YOUR_NAME_HERE Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. You just DO WHAT THE FUCK YOU WANT TO.
 { "name": "summation", "description": "A function to execute a summation in JavaScript. Support for a step function and multiplication", "keywords": [ "math" ] }
 Summation
Expected value: [5050, 5049, -15, 120]
Actual value: