Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed First Class Function Lab #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
// Code your solution in this file!

const drivers = ['Antonia', 'Nuru', 'Amari', 'Mo'];

const returnFirstTwoDrivers = function(drivers) {
return drivers.slice(0,2);
};

const returnLastTwoDrivers = function(drivers) {
return drivers.slice(2);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will grab everything after the 2nd element of the array. .slice(-2) will grab the last two elements of the array. In an array with 4 objects, both will return the same thing, the difference would be present with any other number of elements though.

};

const selectingDrivers = [returnFirstTwoDrivers, returnLastTwoDrivers];

function createFareMultiplier(num) {
return function(x){
return x * num;
}
}

const fareDoubler = createFareMultiplier(2);

const fareTripler = createFareMultiplier(3);

function selectDifferentDrivers(array, func) {
return func(array);
};