ForEach under the hood is from the Yandex developer. Rewrite to the sander from the slide - not working.
-
Hello, everyone! I'm looking at the slides from the JavaScript course, Part 1: Coursera bases and functions, in the second week, author: Physiakov Denis, head of the Yandex Development Service. It's a function for Each under the hood. I'm trying to do everything, as shown on slides, in a sandbox, but I can't. What's the mistake?
let tweet = [ { hashtags: ['wstdays'], likes: 16}, { hashtags: ['html'], likes: 8}, { hashtags: ['wstdays'], likes: 10}, { likes: 7} ];
let result = []; function forEach(callback){ for (let i=0; i<this.length; i++) { callback(this[i], i); }; function filterWts(tweet, index){ let hashtags = tweet.hashtags; if (Array.isArray(hashtags) && hashtags.indexOf('wstdays') !== -1) { result.push(tweet) } } forEach(filterWts)
-
You have a function.
this
so it's supposed to call the object as a method. JSforEach
- it's a mass method, so it's there.this
- is a mass. Put your function in the prototype of the masses or instead.this
Use the additional argument for the type function.forEach( arr, callback )
♪In other words, when you call
forEach(filterWts)
, you don't point out what work needs to be done with your body. Unlike in JSforEach
this is clearly stated before the pointforEach
♪