From 0d38379139790d733913bc28df515723c33310a1 Mon Sep 17 00:00:00 2001 From: Bryant Mercedes Date: Thu, 14 Apr 2022 13:51:18 -0400 Subject: [PATCH] done --- .vscode/settings.json | 3 +++ data/lol.js | 0 package-lock.json | 1 + solution.js | 63 +++++++++++++++++++++++++++++++------------ 4 files changed, 50 insertions(+), 17 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 data/lol.js diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..825ba3d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cSpell.words": ["nums"] +} diff --git a/data/lol.js b/data/lol.js new file mode 100644 index 0000000..e69de29 diff --git a/package-lock.json b/package-lock.json index 7d1ca89..f52962a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "m6-array-method-drills", "version": "1.0.0", "license": "ISC", "devDependencies": { diff --git a/solution.js b/solution.js index 9a01476..6f93972 100644 --- a/solution.js +++ b/solution.js @@ -1,62 +1,91 @@ -const { nums, words } = require("./data/data.js"); +// const { nums, words } = require("./data/data.js"); +const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0]; + +const words = [ + "The", + "quick", + "brown", + "fox", + "jumps", + "over", + "the", + "lazy", + "dog", +]; // Every -const isEveryNumGreaterThan2 = () => { - // +const isEveryNumGreaterThan2 = (nums) => { + return nums.every((num) => num >= 2); }; -const isEveryWordShorterThan7 = () => { - // +const isEveryWordShorterThan7 = (words) => { + if (!words) { + return false; + } + + return words.every((word) => word.length < 7); }; // Filter -const arrayLessThan5 = () => { +const arrayLessThan5 = (nums) => { + return nums.filter((num) => num < 5); // }; -const arrayOddLengthWords = () => { +const arrayOddLengthWords = (words) => { // + return words.filter((word) => word.length % 2 === 1); }; // Find -const firstValDivisibleBy4 = () => { +const firstValDivisibleBy4 = (nums) => { + return nums.find((num) => num % 4 === 0); // }; -const firstWordLongerThan4Char = () => { +const firstWordLongerThan4Char = (words) => { // + return words.find((word) => word.length > 4); }; // For Each const logValuesTimes3 = () => { // + nums.forEach((num) => { + console.log(num * 3); + }); }; const logWordsWithExclamation = () => { - // + words.forEach((num) => { + console.log(num + "!"); + }); }; // Map -const arrayValuesTimes100TimesIndex = () => { +const arrayValuesTimes100TimesIndex = (nums) => { + return nums.map((num, i) => num * num * i); // }; -const arrayWordsUpcased = () => { - // +const arrayWordsUpcased = (words) => { + return words.map((word) => { + return 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 = {