Solution Review: Where to Insert

This lesson will explain the solution to the problem in the previous lesson.

We'll cover the following...

There are various ways to solve the problem provided in the previous lesson. However, the question asks for an efficient solution using arrow functions.

Solution #

Let’s look at the fast-way of solving the problem using arrow functions.

Press + to interact
const getIndex = (arr, number) =>
arr.reduce((counter, curr) => (number > curr ? ++counter : counter), 0);
var inputsA = [[10,5,1,3],[16,4,5]];
var inputsB = [2,13]
console.log(getIndex(inputsA[0],inputsB[0]))

Explanation #

The first part of the question requires you ...