💡tips
arr.containsSubarray() - closure with internal parameter ⭐️
// filter using `thisArg`
const arr = [1,0,2,0,3,0,4,5,6,7,8,9,10,11,12,13,14];
// ⭐️ requires a normal function, doesn't work with arrow functions.
// ╭─── ⭐️ ───╮
const filtered = arr.filter(function(item) {
if (this.count < 10 && item > 0) { // ⭐️ this == thisArg
this.count++;
return true;
}
return false;
}, {count: 0});
// ╰── ⭐️ ──╯ <--- `thisArg`Last updated
Was this helpful?