JS
…
Dashboard/Algorithms/array algorithms

Module 2 of 2

array algorithms

freeCodeCamp-style drills: chunk, flatten, unique, range, two-sum.

Algorithms · 0/8 completed · scroll down for every challenge

Challenge 1 of 8

FizzBuzz value

Instructions

Write `fizzBuzz(n)` — `"Fizz"` if divisible by 3, `"Buzz"` by 5, `"FizzBuzz"` by both, else the number.

Editor

IntelliSense on

// Write your code below

Challenge 2 of 8 · Factorial

Challenge 2 of 8

Factorial

Instructions

Write `factorial(n)` for n >= 0.

Editor

IntelliSense on

// Write your code below

Challenge 3 of 8 · Chunk array

Challenge 3 of 8

Chunk array

Instructions

Write `chunk(arr, size)` splitting into subarrays of length `size` (last may be shorter).

Editor

IntelliSense on

// Write your code below

Challenge 4 of 8 · Flatten deep

Challenge 4 of 8

Flatten deep

Instructions

Write `flatten(arr)` that fully flattens nested arrays.

Editor

IntelliSense on

// Write your code below

Challenge 5 of 8 · Unique keep order

Challenge 5 of 8

Unique keep order

Instructions

Write `unique(arr)` removing duplicates and keeping first-seen order.

Editor

IntelliSense on

// Write your code below

Challenge 6 of 8 · Range

Challenge 6 of 8

Range

Instructions

Write `range(start, end)` inclusive integers from start to end (start <= end).

Editor

IntelliSense on

// Write your code below

Challenge 7 of 8 · Two sum indices

Challenge 7 of 8

Two sum indices

Instructions

Write `twoSum(nums, target)` returning the first pair of indices that add to target.

Editor

IntelliSense on

// Write your code below

Challenge 8 of 8 · Max profit

Challenge 8 of 8

Max profit

Instructions

Write `maxProfit(prices)` — max difference later - earlier price, or 0.

Editor

IntelliSense on

// Write your code below

Next module