2 ms·
Rad! You might be able to save a little time/logic by updating the JavaScript from ES3. Instead of: if(thisText.indexOf(thisWord) > -1) You can just do:
by nailer 10y ago
Rad! You might be able to save a little time/logic by updating the JavaScript from ES3. Instead of:
if(thisText.indexOf(thisWord) > -1)
You can just do:
if ( thisText.includes(thisWord) )
Likewise...
for(let i = 0; i < entries.length; i++){
Can be replaced with:
entries.forEach(function(entry, index){
Chrome supports both the relevant parts of ES6 and ES5 out of the box.
- alistproducer2 10y agothanks for the suggestions. I tend to avoid forEach because of the memory overhead (adds function calls where not really necessary). I guess I'm old school, but never got around to using includes. It's been on my radar for a while. I've always tried to write code that is as portable as possible, even though now, with evergreen browsers in the lead, it doesn't really matter as much.
- nailer 10y agoYeah, .forEach() is a new scope. But the better readability is worth the minor performance impact for everything but the most performance-intensive code.
- drenvuk 10y agoIt's that kind of thinking that gets us really slow software.
- nailer 10y ago"premature optimization is the root of all evil" - Don Knuth Also old-style for loops in JS fall victim to the last entry effect since people often use them to set up event handlers and wonder why they don't work.