Skip to content

Instantly share code, notes, and snippets.

@DeviaVir
Forked from joepie91/functional.js
Last active August 29, 2015 14:19
Show Gist options
  • Save DeviaVir/e8af2ad6dc834c5d35e7 to your computer and use it in GitHub Desktop.
Save DeviaVir/e8af2ad6dc834c5d35e7 to your computer and use it in GitHub Desktop.
// Double all numbers
> Promise.map([1, 2, 3], function(num) { return num * 2; }).then(function(numbers) { console.log("The final list of numbers:", numbers); })
The final list of numbers: [ 2, 4, 6 ]
// Remove all the odd numbers
> Promise.filter([1, 2, 3], function(num) { return (num % 2) == 0; }).then(function(numbers) { console.log("The final list of numbers:", numbers); })
The final list of numbers: [ 2 ]
// Sum all the numbers
> Promise.reduce([1, 2, 3], function(total, num) { return total + num; }, 0).then(function(number) { console.log("The final value:", number); })
The final value: 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment