bhylu.com

Advertisements

JS Examples

Small examples are useful when you change one input and predict the new output. Combine array filtering with a calculation.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const bookings = [2, 0, 4];
const active = bookings.filter(count => count > 0);
console.log(active.reduce((total, count) => total + count, 0));

What happens

The active bookings total 6 places.