This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| case [1, 2, 3] do | |
| [1, 2, 4] -> false | |
| [a, 2, 3] -> true | |
| _ -> true # default condition | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function addTen(x) { | |
| return x + 10; | |
| } | |
| // You can also assign an arrow functions to a variable | |
| const addTen = (x) => x + 10; | |
| addTen(10); // 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add_ten(x) do | |
| x + 10 | |
| end | |
| add_five = fn x -> x + 5 end | |
| add_two = &(&1 + 2) | |
| add_ten(10) # 20 | |
| add_five.(10) # 15 | |
| add_two.(10) # 12 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const addTen = (x = 10) => { | |
| return x + 10; | |
| }; | |
| addTen(); // 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add_ten(x \\ 10) do | |
| x + 10 | |
| end | |
| add_ten() # 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const addTen = (x) => x + 10; | |
| const doAThingToX = (thing, x) => thing(x); | |
| doAThingToX(addTen, 10); // 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_ten = fn (x) -> x + 10 end | |
| do_a_thing_to_x = fn (thing, x) -> | |
| thing.(x) | |
| end | |
| do_a_thing_to_x.(add_ten, 10) # 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function zip(...arrs) { | |
| let i = -1; | |
| return { | |
| [Symbol.iterator]() { | |
| return this; | |
| }, | |
| next: () => ({ | |
| done: ++i === arrs[0].length, | |
| value: arrs.map(arr => arr[i]) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const hashCode = str => Array.from(str) | |
| .reduce((h, c) => Math.imul(31, h) + c.charCodeAt(0) | 0, 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Object.prototype[Symbol.iterator] = function() { | |
| let props = Object.getOwnPropertyNames(this); | |
| return { | |
| next: () => { | |
| let name = props.shift(); | |
| let done = (name === undefined); | |
| let value = (done) ? undefined : [name, this[name]]; | |
| return { value, done }; | |
| } | |
| } |