Skip to content
Open
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
146 changes: 68 additions & 78 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"eslint-plugin-promise": "^5.1.0",
"husky": "^8.0.3",
"jasmine": "^4.6.0",
"nodemon": "^2.0.20",
"nodemon": "^3.1.9",
"prettier": "^2.6.2"
}
}
2 changes: 1 addition & 1 deletion spec/advanced/advanced.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ describe('advanced', () => {

// 6. find the median of the numbers in the array
it('Check median', () => {
expect(median).toBe(3)
expect(median).toBe(3.5)
})
})
34 changes: 33 additions & 1 deletion src/advanced/advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,53 @@ const nums = [1, 10, 3, 9, 4, 8, 5, 7, 6, 2, -5, -2, -4, -9] // eslint-disable-l
// to prove you have done this, set the variable indexOfTen to the iteration index when you find 10
let hasTen = false
let indexOfTen = -1
for (let i = 0; i < nums.length; i++) {
if (nums[i] === 10) {
hasTen = true
indexOfTen = i
break
}
}

// 2. Use a for loop to count how many numbers in the array are divisible by 3
let divisibleByThreeCount = 0

for (const num of nums) {
if (num % 3 === 0) {
divisibleByThreeCount++
}
}
// 3. use a for loop to find the average of the numbers in the array
let average = 0
for (const num of nums) {
average += num
}
average /= nums.length

// 4. use a for loop to find the largest number in the array
let largest = 0
for (const num of nums) {
if (num > largest) {
largest = num
}
}

// 5. use a for loop to find the smallest number in the array
let smallest = 100000
for (const num of nums) {
if (num < smallest) {
smallest = num
}
}

// 6. find the median of the numbers in the array
let median = 0
nums.sort((a, b) => a - b)
if (nums.length % 2 === 0) {
const mid = nums.length / 2
median = (nums[mid - 1] + nums[mid]) / 2
} else {
median = nums[Math.floor(nums.length / 2)]
}

module.exports = {
hasTen,
Expand Down
Loading