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

Solution to Array Method Drills #100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
28 changes: 17 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,71 @@ const { nums, words } = require("./data/data.js");

// Every
const isEveryNumGreaterThan2 = () => {
//
return nums.every((num) => num > 2);
};

const isEveryWordShorterThan7 = () => {
//
return words.every((word) => word.length < 7);
};

// Filter

const arrayLessThan5 = () => {
//
return nums.filter((num) => num < 5);
};

const arrayOddLengthWords = () => {
//
return words.filter((word) => word.length % 2 !== 0);
};

// Find

const firstValDivisibleBy4 = () => {
//
return nums.find((num) => num % 4 === 0);
};

const firstWordLongerThan4Char = () => {
//
return words.find((word) => word.length > 4);
};

// Find Index

const firstNumIndexDivisibleBy3 = () => {
//
return nums.findIndex((num) => num % 3 === 0);
};

const firstWordIndexLessThan2Char = () => {
//
return words.findIndex((word) => word.length < 2);
};

// For Each

const logValuesTimes3 = () => {
//
return nums.forEach((num) => num * 3);
};

const logWordsWithExclamation = () => {
//
return words.forEach((word) => word + "!");
};

// Map

const arrayValuesSquaredTimesIndex = () => {
//
return nums.map((num, i) => num * num * i);
};

const arrayWordsUpcased = () => {
//
return words.map((word) => word.toUpperCase());
};

// Some

const areSomeNumsDivisibleBy7 = () => {
//
return nums.some((num) => num % 7);
};

const doSomeWordsHaveAnA = () => {
//
return words.some((word) => word.includes("a"));
};

module.exports = {
Expand Down