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

D. Morales Array Method Drills #83

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
4 changes: 3 additions & 1 deletion package-lock.json

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

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

// Every
const isEveryNumGreaterThan2 = () => {
//
const isEveryNumGreaterThan2 = (numbers) => {
return numbers.every(number => number>2)//the .Every method return a boolean
};
// console.log(isEveryNumGreaterThan2(nums))

const isEveryWordShorterThan7 = () => {
//


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

// Filter

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

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

// Find

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

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

// Find Index

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

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

// For Each

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

const logWordsWithExclamation = () => {
//
const logWordsWithExclamation = (words) => {
console.log(words.forEach(word => word.includes("!")))
};
// const logWordsWithExclamation = (words) => {
// words.forEach(word => console.log(word[word.length-1] === "!"))
// };
// const logWordsWithExclamation = (words) => {
// words.forEach(word => console.log(word + "!"))
// };
console.log(logWordsWithExclamation(words))

// Map

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

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

// Some

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

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

module.exports = {
Expand Down