Skip to content

Instantly share code, notes, and snippets.

@jimode
Last active August 31, 2018 22:13
Show Gist options
  • Select an option

  • Save jimode/063740bcef79730b7268dfd6ff5e19ad to your computer and use it in GitHub Desktop.

Select an option

Save jimode/063740bcef79730b7268dfd6ff5e19ad to your computer and use it in GitHub Desktop.
Introduction to Currying - JS Bin// source https://jsbin.com/dinahay
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
function greet(greeting) {//, name) {
return function(name) {
return `${greeting} ${name}`;
};
}
console.log(greet('Good evening')('Jimi'));
const friends = ['Nate', 'Jimi', 'Scott', 'Dean'];
// without currying:
// const friendGreetings = friends.map(friend => `Good evening ${friend}`);
// with currying:
const friendGreetings = friends.map(greet('Good evening'));
console.log(friendGreetings);
</script>
<script id="jsbin-source-javascript" type="text/javascript">function greet(greeting) {//, name) {
return function(name) {
return `${greeting} ${name}`;
};
}
console.log(greet('Good evening')('Jimi'));
const friends = ['Nate', 'Jimi', 'Scott', 'Dean'];
// const friendGreetings = friends.map(friend => `Good evening ${friend}`);
const friendGreetings = friends.map(greet('Good evening'));
console.log(friendGreetings);</script></body>
</html>
function greet(greeting) {//, name) {
return function(name) {
return `${greeting} ${name}`;
};
}
console.log(greet('Good evening')('Jimi'));
const friends = ['Nate', 'Jimi', 'Scott', 'Dean'];
// const friendGreetings = friends.map(friend => `Good evening ${friend}`);
const friendGreetings = friends.map(greet('Good evening'));
console.log(friendGreetings);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment