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
139 changes: 64 additions & 75 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.7",
"prettier": "^2.6.2"
}
}
37 changes: 37 additions & 0 deletions src/advanced/advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,57 @@ const nums = [1, 10, 3, 9, 4, 8, 5, 7, 6, 2, -5, -2, -4, -9] // eslint-disable-l
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
nums.forEach((e) => {
if (e % 3 === 0) {
divisibleByThreeCount++
}
})

// 3. use a for loop to find the average of the numbers in the array
let average = 0

for (let i = 0; i < nums.length; i++) {
average += nums[i]
}
average = average / nums.length

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

// 5. use a for loop to find the smallest number in the array
let smallest = 100000

nums.forEach((e) => {
if (smallest > e) {
smallest = e
}
})

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

module.exports = {
hasTen,
Expand Down
Loading