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

array method drills #64

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions package-lock.json

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

67 changes: 43 additions & 24 deletions solution.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,83 @@
const { nums, words } = require("./data/data.js");

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

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

// Filter

const arrayLessThan5 = () => {
//
const arrayLessThan5 = (numbersArr) => {
return numbersArr.filter(number => number < 5);
};

const arrayOddLengthWords = () => {
//
const arrayOddLengthWords = (wordsArr) => {
return wordsArr.filter(word => word.length % 4);
};

// Find

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

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

// For Each

const logValuesTimes3 = () => {
//
const logValuesTimes3 = (numbersArr) => {
return numbersArr.forEach(number => {
console.log(number, number, number)
});
};

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

// Map

const arrayValuesSquaredTimesIndex = () => {
//
const arrayValuesSquaredTimesIndex = (numbersArr) => {
return numbersArr.map((number, index) =>
(Math.pow(number, 2)) * index)
};

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

// Some

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

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


isEveryNumGreaterThan2(nums);
isEveryWordShorterThan7(words);
arrayLessThan5(nums);
arrayOddLengthWords(words);
firstValDivisibleBy4(nums);
firstWordLongerThan4Char(words);
logValuesTimes3(nums)
logWordsWithExclamation(words)
arrayValuesSquaredTimesIndex(nums)
arrayWordsUpcased(words)
areSomeNumsDivisibleBy7(nums)
doSomeWordsHaveAnA(words)

module.exports = {
isEveryNumGreaterThan2,
isEveryWordShorterThan7,
Expand Down