WDD 131: Dynamic Web Fundamentals

W04 Learning Activity: JavaScript Array Functions

Overview

Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. It is a declarative programming paradigm, which means you express your program through expressions or declarations rather than statements. Array methods that support functional programming include filter(), map(), and reduce(). While there are other array methods that support functional programming, this activity focuses on these three common and useful methods.

Course Learning Outcomes
  1. Demonstrate proficiency with JavaScript language syntax.
  2. Use JavaScript to respond to events and dynamically modify HTML.

Prepare

array.filter()

The array.filter() method creates a new array containing only elements that meet a specified condition.

array.map()

The array.map() method transforms each element of an array using a provided function and returns a new array with the transformed elements. The original array is not modified, and the new array has the same number of elements as the original.

array.reduce()

The array.reduce() method reduces an array to a single value by executing a reducer function on each element. The reducer function takes four arguments: accumulator, current value, current index, and source array. The function's returned value updates the accumulator, which is carried through each iteration and becomes the final result.

Check Your Understanding

For all of these exercises, use this array declaration:

let names = ['Nancy','Blessing','Jorge','Svetlana','Bob'];