Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

ES6 Arrow Functions

node v4.9.1
version: 2.0.0
endpointsharetweet
Arrow functions (also known as fat arrow functions) have a shorter syntax compared to traditional function expressions and lexically bind the this value. Arrow functions are also always anonymous. Here we are using the shortest form, where the body is a simple expression and we can drop the parenthesis around the parameter since there is only one:
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // Same as function(number) { return number * 2 } var doubled = numbers.map(number => number * 2);
If we want multiple parameters, we can add the parenthesis and curly braces back:
// Same as function(runningTotal, number) { return runningTotal + number } var sum = numbers.reduce((runningTotal, number) => runningTotal + number, 0);
Finally, more complex multistatement arrow functions can use curly braces:
// Here all we're really saving is the function() heading. numbers.map(number => { if (number % 3 == 0 && number % 5 === 0) return "Fizz Buzz"; if (number % 3 === 0) return "Fizz"; if (number % 5 === 0) return "Buzz"; return number; }).join("<br/>")
Arrow functions can also make your code less complex since they'll use the "this" of the surrounding scope, instead of introducing their own. This means you can avoid having to bind in many cases:
var cart = { items: [], addItem: function(anItem) { console.log("Added " + anItem + "!"); this.items.push(anItem); }, addAll: function(newItems) { // Before we'd have to do (function(anItem) { this.addItem(anItem) }).bind(this) newItems.forEach(anItem => this.addItem(anItem)); } } cart.addAll(["pickels", "tomatoes", "cheese"])
To learn more about arrow functions, check out https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/ Some of these examples and explanations originally taken and modified from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions https://github.com/lukehoban/es6features#arrows https://en.wikipedia.org/wiki/Fizz_buzz
Loading…

56 comments

  • posted 4 years ago by araid-en10
    What tool root #q
  • posted 4 years ago by kevitalin39
    Tool root #q
  • posted 4 years ago by adrieljaredtubong
    Good
  • posted 4 years ago by jackpot1136
    I have to say thank you for your help.
  • posted 3 years ago by comyoussef
    Goood
  • posted 3 years ago by sherrielee
    Please can you help i dont understand this its not working
  • posted 3 years ago by doge344
    Doge1223
  • posted 3 years ago by shenk0786
    Please help on this
  • posted 3 years ago by stsl
    чудово
  • posted 3 years ago by tamu18115
    automobileservices.org
  • posted 3 years ago by chatjan0922
    KASITHBK
  • posted 3 years ago by nelson1576
    Please help me out
  • posted 3 years ago by 5b899289de269400127763f4
    Ayuda por fabor
  • posted 3 years ago by cashcashn
    I can't figure out guys umm umm
  • posted 3 years ago by sohelshaikh5465
    Sohel shaikh 5465
  • posted 3 years ago by viloka
    I need some helping hands here
  • posted 3 years ago by anspage
    @anspage
  • posted 2 years ago by dgb
    MU
  • posted 2 years ago by murdy
    Murdy
  • posted 2 years ago by malayanhac
    good morning to all SIFU And MahaGuru, i dont know what the mission today, malaysia amex huntersWas RIP.
  • posted 2 years ago by because67
    How do I delete this account
  • posted 2 years ago by wow
    https://github.com/password_reset/AJHZT4HTEQ44HWJUPPFXN7K47TMYTA5FMVWWC2LMWNTW6ZDZM5XW63DFIBTW2YLJNQXGG33NUVTG64TDMXBLG5DXN5PWMYLDORXXEX3WMVZGSZTJMVSME
  • posted 2 years ago by ultraprecisekamal
    ()=>`Thank you runkit team`
  • posted 2 years ago by 5d44a5261549b3001313407f
    Ass
  • posted 2 years ago by 5d5d647b2ddea900148b41fe
    https://dioulde.home.blog https://diouldehome.wordpress.com https://diouldebaldehome.wordpress.com Pourquoi ça ne reduise pas en 1?
  • posted 2 years ago by 5db066a397504b001306620e
    https://m.adam4adam.com/
  • posted a year ago by 5e486b9907092500138c7ac5
    Runkit Save Account ES6 Arrow Functions node v4.9.1version: 2.0.0endpointsharetweet Arrow functions (also known as fat arrow functions) have a shorter syntax compared to traditional function expressions and lexically bind the this value. Arrow functions are also always anonymous. ​ Here we are using the shortest form, where the body is a simple expression and we can drop the parenthesis around the parameter since there is only one: 1 var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; 2 ​ 3 // Same as function(number) { return number * 2 } 4 var doubled = numbers.map(number => number * 2); [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] If we want multiple parameters, we can add the parenthesis and curly braces back: 5 // Same as function(runningTotal, number) { return runningTotal + number } 6 var sum = numbers.reduce((runningTotal, number) => runningTotal + number, 0); 55 Finally, more complex multistatement arrow functions can use curly braces: 7 // Here all we're really saving is the function() heading. 8 numbers.map(number => 9 { 10 if (number % 3 == 0 && number % 5 === 0) 11 return "Fizz Buzz"; 12 ​ 13 if (number % 3 === 0) 14 return "Fizz"; 15 ​ 16 if (number % 5 === 0) 17 return "Buzz"; 18 19 return number; 20 }).join("<br/>") "1<br/>2<br/>Fizz<br/>4<br/>Buzz<br/>Fizz<br/>7<br/>8<br/>Fizz<br/>Buzz" Arrow functions can also make your code less complex since they'll use the "this" of the surrounding scope, instead of introducing their own. This means you can avoid having to bind in many cases: 21 var cart = 22 { 23 items: [], 24 addItem: function(anItem) 25 { 26 console.log("Added " + anItem + "!"); 27 this.items.push(anItem); 28 }, 29 addAll: function(newItems) 30 { 31 // Before we'd have to do (function(anItem) { this.addItem(anItem) }).bind(this) 32 newItems.forEach(anItem => this.addItem(anItem)); 33 } 34 } 35 ​ 36 cart.addAll(["pickels", "tomatoes", "cheese"]) "Added pickels!" "Added tomatoes!" "Added cheese!" undefined To learn more about arrow functions, check out https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/ ​ Some of these examples and explanations originally taken and modified from: ​ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions https://github.com/lukehoban/es6features#arrows https://en.wikipedia.org/wiki/Fizz_buzz 26 comments posted 3 years ago by araid-en10 What tool root #q posted 3 years ago by kevitalin39 Tool root #q posted 2 years ago by adrieljaredtubong Good posted 2 years ago by jackpot1136 I have to say thank you for your help. posted 2 years ago by comyoussef Goood posted 2 years ago by sherrielee Please can you help i dont understand this its not working posted 2 years ago by doge344 Doge1223 posted 2 years ago by shenk0786 Please help on this posted 2 years ago by stsl чудово posted 2 years ago by tamu18115 automobileservices.org posted a year ago by chatjan0922 KASITHBK posted a year ago by nelson1576 Please help me out posted a year ago by 5b899289de269400127763f4 Ayuda por fabor posted a year ago by cashcashn I can't figure out guys umm umm posted a year ago by sohelshaikh5465 Sohel shaikh 5465 posted a year ago by viloka I need some helping hands here posted a year ago by anspage @anspage posted a year ago by dgb MU posted a year ago by murdy Murdy posted a year ago by malayanhac good morning to all SIFU And MahaGuru, i dont know what the mission today, malaysia amex huntersWas RIP. posted 10 months ago by because67 How do I delete this account posted 8 months ago by wow https://github.com/password_reset/AJHZT4HTEQ44HWJUPPFXN7K47TMYTA5FMVWWC2LMWNTW6ZDZM5XW63DFIBTW2YLJNQXGG33NUVTG64TDMXBLG5DXN5PWMYLDORXXEX3WMVZGSZTJMVSME posted 8 months ago by ultraprecisekamal ()=>`Thank you runkit team` posted 6 months ago by 5d44a5261549b3001313407f Ass posted 6 months ago by 5d5d647b2ddea900148b41fe https://dioulde.home.blog https://diouldehome.wordpress.com https://diouldebaldehome.wordpress.com Pourquoi ça ne reduise pas en 1? posted 3 months ago by 5db066a397504b001306620e https://m.adam4adam.com/ Add a comment
  • posted a year ago by nhatthanhlatao
    Runkit Save Account ES6 Arrow Functions node v4.9.1version: 2.0.0endpointsharetweet Arrow functions (also known as fat arrow functions) have a shorter syntax compared to traditional function expressions and lexically bind the this value. Arrow functions are also always anonymous. ​ Here we are using the shortest form, where the body is a simple expression and we can drop the parenthesis around the parameter since there is only one: 1 var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; 2 ​ 3 // Same as function(number) { return number * 2 } 4 var doubled = numbers.map(number => number * 2); [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] If we want multiple parameters, we can add the parenthesis and curly braces back: 5 // Same as function(runningTotal, number) { return runningTotal + number } 6 var sum = numbers.reduce((runningTotal, number) => runningTotal + number, 0); 55 Finally, more complex multistatement arrow functions can use curly braces: 7 // Here all we're really saving is the function() heading. 8 numbers.map(number => 9 { 10 if (number % 3 == 0 && number % 5 === 0) 11 return "Fizz Buzz"; 12 ​ 13 if (number % 3 === 0) 14 return "Fizz"; 15 ​ 16 if (number % 5 === 0) 17 return "Buzz"; 18 19 return number; 20 }).join("<br/>") "1<br/>2<br/>Fizz<br/>4<br/>Buzz<br/>Fizz<br/>7<br/>8<br/>Fizz<br/>Buzz" Arrow functions can also make your code less complex since they'll use the "this" of the surrounding scope, instead of introducing their own. This means you can avoid having to bind in many cases: 21 var cart = 22 { 23 items: [], 24 addItem: function(anItem) 25 { 26 console.log("Added " + anItem + "!"); 27 this.items.push(anItem); 28 }, 29 addAll: function(newItems) 30 { 31 // Before we'd have to do (function(anItem) { this.addItem(anItem) }).bind(this) 32 newItems.forEach(anItem => this.addItem(anItem)); 33 } 34 } 35 ​ 36 cart.addAll(["pickels", "tomatoes", "cheese"]) "Added pickels!" "Added tomatoes!" "Added cheese!" undefined To learn more about arrow functions, check out https://hacks.mozilla.org/2015/06/es6-in-depth-arrow-functions/ ​ Some of these examples and explanations originally taken and modified from: ​ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions https://github.com/lukehoban/es6features#arrows https://en.wikipedia.org/wiki/Fizz_buzz 26 comments posted 3 years ago by araid-en10 What tool root #q posted 3 years ago by kevitalin39 Tool root #q posted 2 years ago by adrieljaredtubong Good posted 2 years ago by jackpot1136 I have to say thank you for your help. posted 2 years ago by comyoussef Goood posted 2 years ago by sherrielee Please can you help i dont understand this its not working posted 2 years ago by doge344 Doge1223 posted 2 years ago by shenk0786 Please help on this posted 2 years ago by stsl чудово posted 2 years ago by tamu18115 automobileservices.org posted a year ago by chatjan0922 KASITHBK posted a year ago by nelson1576 Please help me out posted a year ago by 5b899289de269400127763f4 Ayuda por fabor posted a year ago by cashcashn I can't figure out guys umm umm posted a year ago by sohelshaikh5465 Sohel shaikh 5465 posted a year ago by viloka I need some helping hands here posted a year ago by anspage @anspage posted a year ago by dgb MU posted a year ago by murdy Murdy posted a year ago by malayanhac good morning to all SIFU And MahaGuru, i dont know what the mission today, malaysia amex huntersWas RIP. posted 10 months ago by because67 How do I delete this account posted 8 months ago by wow https://github.com/password_reset/AJHZT4HTEQ44HWJUPPFXN7K47TMYTA5FMVWWC2LMWNTW6ZDZM5XW63DFIBTW2YLJNQXGG33NUVTG64TDMXBLG5DXN5PWMYLDORXXEX3WMVZGSZTJMVSME posted 8 months ago by ultraprecisekamal ()=>`Thank you runkit team` posted 6 months ago by 5d44a5261549b3001313407f Ass posted 6 months ago by 5d5d647b2ddea900148b41fe https://dioulde.home.blog https://diouldehome.wordpress.com https://diouldebaldehome.wordpress.com Pourquoi ça ne reduise pas en 1? posted 3 months ago by 5db066a397504b001306620e https://m.adam4adam.com/ Add a comment
  • posted a year ago by cutmuetia
    Cutmuetia1998 V.1.0.0
  • posted a year ago by alfian878787
    https://github.com/mizuka-wu/git-mirror-action/blob/ccf4b66c8441ea570ac13a06aacfc94ccc9ba36d/git-mirror.sh
  • posted a year ago by w5g
    Hello World
  • posted a year ago by fc5gl
    exports.endpoint = function(request, response) { // your code goes here }
  • posted a year ago by fc5gl
    exports.endpoint = function(request, response) { // your code goes here }
  • posted a year ago by fc5gl
    Missassug A20s
  • posted a year ago by fc5gl
    Liverar sansug a20s
  • posted a year ago by fc5gl
    Sansug a20s desbloquear
  • posted a year ago by pierre030
    run
  • posted a year ago by 5f18c5cd819d4d001ab8c527
    Albrg.com
  • posted 10 months ago by 5f48df306db183001a393ef2
    deme @@??
  • posted 8 months ago by sacidmohamed45
    I_mascud
  • posted 8 months ago by mdshakibhosain45
    Run
  • posted 7 months ago by mike1978
    ffuvk alll yoou biichs
  • posted 7 months ago by mike1978
    iifuck any niigge
  • posted 7 months ago by 444hasa4
    // Here all we're really saving is the function() heading. numbers.map(number => { if (number % 3 == 0 && number % 5 === 0) return "Fizz Buzz"; if (number % 3 === 0) return "Fizz"; if (number % 5 === 0) return "Buzz"; return number; }).join("<br/>")
  • posted 6 months ago by hongtaekim3
    : Welcome to the first Maverick challenge for PROJECT SPARK.Project Spark builds a voice-based note-taking artificial intelligence assistant that records, transcribes, and provides insights for voice conversation in near real time. We will release development and design Maverick challenges over the next several months to build this functionality in iterations - you can find these by searching for "Project Spark."  Objective This first challenge requires you to build a speech-to-text transcription tool that accurately creates high quality transcriptions for live voice conversations and distinguishes between different speakers by partitioning text into segments associated with each speaker. You will build a speech recognition tool that applies speaker diarization (https://ai.googleblog.com/2018/11/accurate-online-speaker-diarization.html).   Requirements Assume there are two speakers (Speaker A and Speaker B). As text is spoken into microphone, the tool converts the voice to text with accuracy greater than 80%.Partition each speaker’s text into its own paragraph (Speaker Diarization). For example:Speaker A: Good morning. I’m glad you could join the meeting. How are you?Speaker B: I’m great, how are you?Speaker A: Doing well. Let’s go ahead and get started.Speaker B: Sure thing. The first thing I want to discuss is the agenda.Low latency - response time should be near real-time for speech-to-text transcription.Identify pauses and punctuation commands to ensure that transcriptions are grammatically sound.Show transcription on screen.The tool should be able to sync and work with both live meeting audio as well as historic meeting recordings.Use open-source tools and libraries for the solution. Google has open source core algorithms around this you may use as well as more details: https://ai.googleblog.com/2018/11/accurate-online-speaker-diarization.htmlKeep the solution lightweight for ease of deployability.   HTML (Not required, but if included in code, please follow guidelines below) Comments preferred on all page elements to explain code usage for future developers to understand how you used your code.Clean INDENTATION for all HTML code preferred.HTML code naming should not have any conflicts or errors.Element and Attribute names should be in lowercase and use a "-" or camel naming to separate multiple-word classes (i.e.. "main-content", or "mainContent).Semantically correct tags preferred - use H tags for headers, etc. Use strong and em tags instead of bold and italic tags.Avoid inline CSS styles - all styles should be placed in an external stylesheet.Please validate your code - comment your reason for any validation errors.   CSS (Not required, but if included in code, please follow guidelines below) Use CSS3 Media Queries to load different styles for each page. Avoid building a different page for different device/layout.You should use LESSin the project.Provide comments on the CSS code. Please provide CSS comments to give a clear explanation of the code usage. The goal is to help future developers understand the code.Please use clean INDENTATION for all CSS so developers can follow the code.All CSS naming should avoid any conflicts.As possible use CSS3 style when creating all styling.Use CSS to space out objects, not clear/transparent images (GIFs or PNGs) and use proper structural CSS to lay out your page.Only use table tags for tables of data/information and not for page layout.  JS (Not required, but if included in code, please follow guidelines below) You should use your own scripts or scripts that are free, publicly available, and do not have copyright statements or author recognition requirements in the code.All JavaScript should not have copyright by a third party.   Documentation Please provide documentation around your approach to the solution and any details needed to iterate on the solution.   Licenses & Attribution Third-party assets used to build your item must be properly licensed or free for commercial use. MIT, some modified BSD, Apache 2 licenses are sufficient. Sufficient information regarding third-party assets must be present in your documentation. This includes the author, license info, and a direct link to the asset online.  
  • posted 5 months ago by 6006d4c759f64a001a4bf442
    n.suo
  • posted 5 months ago by queen300
    JsxjsoJsxjsoaJsxjsoaksso
  • posted 5 months ago by mass59
    runkit
  • posted 5 months ago by divasinbox81
    Run
  • posted 4 months ago by chriswheeler
    Keep my acounts fom getgetting hacked
  • posted 4 months ago by chriswheeler
    Keep acounts private
  • posted 3 months ago by a188896
    okay
  • posted 2 months ago by pattanawichiwong
    รรัรรรรรัรรรรัรรรัรรรัรรรรรัรรรรรรัรรรรรัรรรรัรรรัรรรัรรรรรัรรรรรัรรรรรัรรรรัรรรัรรรัรรรรรัรรรรัรรรรรัรรรรัรรรัรรรัรรรรรัรรรัรรรรรัรรรรัรรรัรรรัรรรรรัรรัรรรรรัรรรรัรรรัรรรัรรรรรรรัรรรรรัรรรรัรรรัรรรัรรรรรรัรรรรรัรรรรัรรรัรรรัรรรรรัรรรรรัรรรรัรรรัรรรัรรรรัรรรรรัรรรรัรรรัรรรัรรรัรรรรรัรรรรัรรรัรรรัรรัรรรรรัรรรรัรรรัรรรรรัรรรรรัรรรรัรรรัรรรรัรรรรรัรรรรัรรรัรรรัรรรรรัรรรรัรรรัรรัรรรรรัรรรรัรรรรรัรรรรรัรรรรัรรรรัรรรรรัรรรรัรรรัรรรรรัรรรรัรรัรรรรรัรรรรรรัรรรรรัรรรรรัรรรรรัรรรรัรรรรรัรรรัรรรรรัรรัรรรฌผโบนัสของกุยังไงควย
  • posted 2 months ago by lokera07
    Carry on trading
  • posted a month ago by simioblac
    Keep my account getting hached
  • posted 18 days ago by syamsulhuda
    1382141558

sign in to comment