Consider this piece of javascript code:
cont groups = [{ name: 'Sean', type: 'A' },
{ name: 'Jen', type: 'A' },
{ name: 'Tom', type: 'B'}]
for(const group of groups.filter(g => g.type === 'A')) {
...do some work
}
Would the for loop re-evaluate the groups filter each iteration? How would one go about testing that? In this example it does not matter much, however, on large collections it may be important to instead lift the filter operation out into its own variable.