REQUEST A DEMO

Tag: Gary L. Cox

Functional Javascript

javascript
December 3, 2015 Improving my own javascript style... Here at Dovetail, developers are encouraged to keep themselves current with today's coding practice.  Last year, I started studying functional coding to improve my javascript style, along with learning to write cleaner maintainable code.  The easiest way to explain is to take some code and we will begin to refactor it.  Here is a good example: function findUserByName(name, data) { for (var i=0; i<data.length; i++) { if (data[i].name === name) { return data[i]; } } return undefined; } function removeUserByName(name, data) { for (var i=0; i<data.length; i++) { if (data[i].name === name) { data.splice(i, 1); } } return data; } ... var users = [{name: 'John Doe'}, {name: 'Jane Doe'}, {name: 'Henry Smith'}]; findUserByName('John Doe', users); // returns {name: 'John Doe'} ... // Later in some code we want to remove the user removeUserByName('John Doe', users); Red…