From a41912026ef0ed3630df6fe929aa0f436eddd805 Mon Sep 17 00:00:00 2001 From: JosteinRuen <99617155+JosteinRuen@users.noreply.github.com> Date: Thu, 26 Sep 2024 08:50:30 +0200 Subject: [PATCH 1/2] Core and ext done --- .husky/pre-commit | 4 ---- src/for-loop-and-arrays.js | 18 ++++++++++++++++-- src/for-loop-basic.js | 15 ++++++++++++--- 3 files changed, 28 insertions(+), 9 deletions(-) delete mode 100644 .husky/pre-commit diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100644 index 6b54e0b..0000000 --- a/.husky/pre-commit +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -npx eslint src diff --git a/src/for-loop-and-arrays.js b/src/for-loop-and-arrays.js index 6635155..bf3b2fa 100644 --- a/src/for-loop-and-arrays.js +++ b/src/for-loop-and-arrays.js @@ -6,18 +6,32 @@ let word = '' // eslint-disable-line prefer-const // TODO: Add code below this line to make the tests pass // 1. Use a for loop to set the sum variable to the sum of all the values in nums - +for(let i = 0; i < nums.length; i++){ + sum += nums[i] +} // 2. Use a for loop to populate doubledNums with every value from nums array doubled (i.e [2, 6, 24, etc...]) const doubledNums = [] +for(let i = 0; i < nums.length; i++){ + doubledNums.push(nums[i] * 2) +} // 3. Use a for loop to set word variable equal to all the letters in the letters array combined as a single string - +for(let i = 0; i < letters.length; i++){ + word += letters[i] +} // 4. Use a for loop to populate everySecondNum with every second number from the nums array const everySecondNum = [] +for(let i = 0; i < nums.length; i+=2){ + everySecondNum.push(nums[i]) +} // 5. Use a for loop to populate numsReversed with the numbers from nums in reverse order const numsReversed = [] +for(let i = nums.length; i >= 0; i --){ + numsReversed.push(nums[i]) +} + // do not change below this line module.exports = { a: sum, diff --git a/src/for-loop-basic.js b/src/for-loop-basic.js index dc3775a..61aac7a 100644 --- a/src/for-loop-basic.js +++ b/src/for-loop-basic.js @@ -4,13 +4,22 @@ const evenNums = [] const countdown = [] // TODO: 1. Write a for loop that adds the numbers 0 to 3 to the numsZeroToThree array - +for(let i=0; i<= 3; i++) numsZeroToThree.push(i) // TODO: 2. Write a for loop that adds the numbers 5 to 10 to the numsFiveToTen array - +for(let i=5; i<= 10; i++){ + numsFiveToTen.push(i) +} // TODO: 3. Write a for loop that adds all the even numbers between 0 and 6 (0, 2, 4, 6) to evenNums +for(let i = 0; i <= 6; i++){ + if(i%2 === 0){ + evenNums.push(i) + } +} // TODO: 4. Write a for loop that adds the numbers 3 to 0 (in that order) to the countdown array - +for(let i = 3; i >=0; i--){ + countdown.push(i) +} // do not change below this line module.exports = { a: numsZeroToThree, From 9de604e5d4ecac564a93fd0dff89f46d95785dd4 Mon Sep 17 00:00:00 2001 From: JosteinRuen <99617155+JosteinRuen@users.noreply.github.com> Date: Thu, 26 Sep 2024 08:57:44 +0200 Subject: [PATCH 2/2] Update for-loop-and-arrays.js --- src/for-loop-and-arrays.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/for-loop-and-arrays.js b/src/for-loop-and-arrays.js index bf3b2fa..425b454 100644 --- a/src/for-loop-and-arrays.js +++ b/src/for-loop-and-arrays.js @@ -21,14 +21,14 @@ for(let i = 0; i < letters.length; i++){ } // 4. Use a for loop to populate everySecondNum with every second number from the nums array const everySecondNum = [] -for(let i = 0; i < nums.length; i+=2){ +for(let i = 1; i < nums.length; i+=2){ everySecondNum.push(nums[i]) } // 5. Use a for loop to populate numsReversed with the numbers from nums in reverse order const numsReversed = [] -for(let i = nums.length; i >= 0; i --){ +for(let i = nums.length -1; i >= 0; i --){ numsReversed.push(nums[i]) }