Skip to content

Instantly share code, notes, and snippets.

@frewsxcv
Forked from dherman/short-functions.js
Created March 10, 2012 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frewsxcv/2012315 to your computer and use it in GitHub Desktop.
Save frewsxcv/2012315 to your computer and use it in GitHub Desktop.
using -> for concise functions and => for TCP functions
// non-TCP, shorter function
a.some((x) → {
if (invalid(x))
return true;
console.log(x);
})
// maximally concise, implicit return
a.map((x) → x * 17)
// preserves this-binding
CSVReader.prototype.read = function(str) {
return str.split(/\n/)
.map((line) → line.split(this.regexp));
};
// using loop controls from within TCP functions
// compare and contrast with: https://gist.github.com/1609202
Mailbox.prototype.extractContents = function(contacts) {
for (let a = this.messages, i = 0, n = a.length; i < n; i++) {
a[i].headers.forEach((header) → do {
if (header.isSpam())
continue; // could use a label but unnecessary
let addresses = header.extractAddresses();
addresses.forEach((addr) → {
contacts.add(addr.name, addr.email);
});
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment