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

every, filter and find #12

Open
wants to merge 3 commits into
base: main
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
59 changes: 28 additions & 31 deletions solution.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,69 @@
const { nums, words } = require("./data/data.js");

// Every
const isEveryNumGreaterThan2 = () => {
//
const isEveryNumGreaterThan2 = (numbers) => {
return numbers.every((number)=> number > 2)
};

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

// Filter

const arrayLessThan5 = () => {
//
const arrayLessThan5 = (array) => {
return array.filter((element) => element < 5)
};

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

// Find

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

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

// Find Index

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

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

// For Each

const logValuesTimes3 = () => {
//
const logValuesTimes3 = (array) => {
return array.forEach((number) => number*3)
};

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

// Map

const arrayValuesSquaredTimesIndex = () => {
//
const arrayValuesSquaredTimesIndex = (array) => {
return array.map((number) => number * number * (array.indexOf(number)))
};

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

// Some

const areSomeNumsDivisibleBy7 = () => {
//
const areSomeNumsDivisibleBy7 = (array) => {
return array.some((number) => number % 7 === 0)
};

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

module.exports = {
Expand Down