Problem at Introduction To JavaScript, Iterator Documentation section


#1

Hi all. Can someone please explain me this piece of code? I don’t understand it. Thank you in advance.

console.log(interestingWords.every(word => word.length > 5));

Why is “word => word.length > 5” inside parentheses?


Full code
let words = ['unique', 'uncanny', 'pique', 'oxymoron', 'guise'];

// Something is missing in the method call below

console.log(words.some(function(word) {
  return word.length < 6;
}));

// Use filter to create a new array
let interestingWords = words.filter(function(filteredWords){
  return filteredWords.length > 5;
});

// Make sure to uncomment the code below and fix the incorrect code before running it

console.log(interestingWords.every(word => word.length > 5));


#2

Assuming that interestingWords is an array, the .every() method tests each element passed into the array – in this case it is testing word => word.length> 5 whether every string within the array has a character length greater than 5


#3

Thank you for the answer, now I get it. :slight_smile:


#4

This topic was automatically closed after 7 days. New replies are no longer allowed.