It’s rare that I’m disappointed by the JavaScript language not having a function that I need. One such case was summing an array of numbers — I was expecting Math.sum
or a likewise, baked in API. Fear not — summing an array of numbers is easy using Array.prototype.reduce
!
const numbers = [1, 2, 3, 4]; const sum = numbers.reduce((a, b) => a + b, 0);
The 0
represents the starting value while with a
and b
, one represents the running total with the other representing the value to be added. You’ll also note that using reduce
prevents side effects! I’d still prefer something like Math.sum(...numbers)
but a simple reduce
will do!
Create a CSS Flipping Animation
CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there’s…
Facebook Open Graph META Tags
It’s no secret that Facebook has become a major traffic driver for all types of websites. Nowadays even large corporations steer consumers toward their Facebook pages instead of the corporate websites directly. And of course there are Facebook “Like” and “Recommend” widgets on every website. One…
CSS Custom Cursors
Remember the Web 1.0 days where you had to customize your site in every way possible? You abused the scrollbars in Internet Explorer, of course, but the most popular external service I can remember was CometCursor. CometCursor let you create and use loads of custom cursors for…
MooTools 1.2 Image Protector: dwProtector
Image protection is a hot topic on the net these days, and why shouldn’t it be? If you spent two hours designing an awesome graphic, would you want it ripped of in matter of seconds? Hell no! That’s why I’ve created an image…
[ad_2]