ecmascript-6

Javascript reduce() to find the shortest word in a string

南楼画角 提交于 2021-02-07 04:20:33
问题 I have a function that finds the longest word in a string. function findLongestWord(str) { var longest = str.split(' ').reduce((longestWord, currentWord) =>{ return currentWord.length > longestWord.length ? currentWord : longestWord; }, ""); return longest; } console.log(findLongestWord("The quick brown fox jumped over the lazy dog")); I'm having a hard time converting this to find the shortest word. Why can't I just change currentWord.length > longestWord.length to currentWord.length <

Javascript reduce() to find the shortest word in a string

孤者浪人 提交于 2021-02-07 04:18:02
问题 I have a function that finds the longest word in a string. function findLongestWord(str) { var longest = str.split(' ').reduce((longestWord, currentWord) =>{ return currentWord.length > longestWord.length ? currentWord : longestWord; }, ""); return longest; } console.log(findLongestWord("The quick brown fox jumped over the lazy dog")); I'm having a hard time converting this to find the shortest word. Why can't I just change currentWord.length > longestWord.length to currentWord.length <

Javascript reduce() to find the shortest word in a string

家住魔仙堡 提交于 2021-02-07 04:17:26
问题 I have a function that finds the longest word in a string. function findLongestWord(str) { var longest = str.split(' ').reduce((longestWord, currentWord) =>{ return currentWord.length > longestWord.length ? currentWord : longestWord; }, ""); return longest; } console.log(findLongestWord("The quick brown fox jumped over the lazy dog")); I'm having a hard time converting this to find the shortest word. Why can't I just change currentWord.length > longestWord.length to currentWord.length <

Javascript reduce() to find the shortest word in a string

若如初见. 提交于 2021-02-07 04:17:16
问题 I have a function that finds the longest word in a string. function findLongestWord(str) { var longest = str.split(' ').reduce((longestWord, currentWord) =>{ return currentWord.length > longestWord.length ? currentWord : longestWord; }, ""); return longest; } console.log(findLongestWord("The quick brown fox jumped over the lazy dog")); I'm having a hard time converting this to find the shortest word. Why can't I just change currentWord.length > longestWord.length to currentWord.length <

ES6 Classes ability to perform polymorphism

走远了吗. 提交于 2021-02-07 03:18:46
问题 I am trying to emulate polymorphism through ES6 Classes, in order to be able to better understand this theory. Concept is clear ( designing objects to share behaviors and to be able to override shared behaviors with specific ones ) but I am afraid my code above is not a valid polymorphism example. Due to my lack of experience, I appreciate if you answer these questions in a comprehensive way: The fact that both Classes have an equally named method, and that instances made from each Class get

ES6 Classes ability to perform polymorphism

…衆ロ難τιáo~ 提交于 2021-02-07 03:17:59
问题 I am trying to emulate polymorphism through ES6 Classes, in order to be able to better understand this theory. Concept is clear ( designing objects to share behaviors and to be able to override shared behaviors with specific ones ) but I am afraid my code above is not a valid polymorphism example. Due to my lack of experience, I appreciate if you answer these questions in a comprehensive way: The fact that both Classes have an equally named method, and that instances made from each Class get

ES6 Classes ability to perform polymorphism

旧时模样 提交于 2021-02-07 03:15:45
问题 I am trying to emulate polymorphism through ES6 Classes, in order to be able to better understand this theory. Concept is clear ( designing objects to share behaviors and to be able to override shared behaviors with specific ones ) but I am afraid my code above is not a valid polymorphism example. Due to my lack of experience, I appreciate if you answer these questions in a comprehensive way: The fact that both Classes have an equally named method, and that instances made from each Class get

Get the Value of HTML Attributes Using Puppeteer

喜你入骨 提交于 2021-02-07 02:42:34
问题 Using Puppeteer, I've selected some HTML elements using: await page.$$( 'span.styleNumber' ); I can get the element's text using: console.log( await ( await styleNumber.getProperty( 'innerText' ) ).jsonValue() ); How can I the value of the element's data-Color attribute? Here is my script: HTML <span class="styleNumber" data-Color="Blue">SG1000</span> <span class="styleNumber" data-Color="Green">SG2000</span> <span class="styleNumber" data-Color="Red">SG3000</span> Puppeteer const puppeteer =

Get the Value of HTML Attributes Using Puppeteer

那年仲夏 提交于 2021-02-07 02:41:18
问题 Using Puppeteer, I've selected some HTML elements using: await page.$$( 'span.styleNumber' ); I can get the element's text using: console.log( await ( await styleNumber.getProperty( 'innerText' ) ).jsonValue() ); How can I the value of the element's data-Color attribute? Here is my script: HTML <span class="styleNumber" data-Color="Blue">SG1000</span> <span class="styleNumber" data-Color="Green">SG2000</span> <span class="styleNumber" data-Color="Red">SG3000</span> Puppeteer const puppeteer =

What is the benefit importing React, {Component} instead of just React?

こ雲淡風輕ζ 提交于 2021-02-06 15:17:33
问题 What is the major benefit of writing import React, { Component } from 'react'; class Link extends Component { ... } instead of import React from 'react'; class Link extends React.Component { ... } when it comes to react 15.4.x?? In my perspective and in my case (correct me if I am wrong) it does not matter at all since: I am using a webpack2 for making my bundles; I use code splitting to split my app code from vendor code; I use webpack.optimize.CommonsChunkPlugin plugin with minChunks: