Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //problem solving (primer)
- //Data structure (how you should structure data) and algorithm(steps to take to solve a problem ) (coding efficiency)
- //How to approach a problem
- //Break down the problem into smaller one
- //subject percentage
- //must pass all subject
- function checkPercentage(arr) {
- //must pass all subject
- let isPassed = true
- let marks = 0
- //looping all items
- for (let num of arr) {
- console.log(num)
- //condition
- if (num < 33) {
- isPassed = false
- break
- } else {
- // total subject number
- marks += num
- }
- }
- if (!false) {
- return false
- }
- return marks / arr.length
- // if (isPassed) {
- // // get an average total Number /total number of subject
- // return marks / arr.length
- // } else {
- // return false
- // }
- }
- console.log(checkPercentage([70, 90, 70, 80]))
- // function max(numArr){
- // let maxNum = numArr[0]
- // // for(let num of numArr){
- // // if(num > maxNum){
- // // maxNum = num
- // // }
- // // }
- // // maxNum = Math.max(...numArr)
- // return Math.max.apply(null, numArr)
- // }
- // console.log(max([70, 90, 88, 80, 100, 10]))
- // function diff(numArr) {
- // let maxNum = numArr[0]
- // let minNum = numArr[0]
- // for (let num of numArr) {
- // if (num > maxNum) {
- // maxNum = num
- // }
- // if (num < minNum) {
- // minNum = num
- // }
- // }
- // return maxNum - minNum
- // }
- // console.log(diff([70, 90, 88, 80, 100, 10]))
- //comparing array
- //Reference
- function compareArr(arr1, arr2) {
- // console.log(arr1.toString())
- // console.log(arr2.toString())
- // if (arr1.toString() === arr2.toString()) {
- // return true
- // }
- // return false
- /// approach 1
- // let result = true
- // if (arr1.length !== arr2.length) {
- // result = false
- // } else {
- // for (let i = 0; i < arr1.length; i++) {
- // console.log(i)
- // if (arr1[i] !== arr2[i]) {
- // result = false
- // break
- // }
- // }
- // }
- // return result
- // // approach 2
- // }
- // console.log(compareArr([1, 2, 3, 4], [1, 2, 3, 4])) //true/false)
- function range(min, max) {
- let arr = []
- for (let i = min; i <= max; i += 2) {
- console.log(i)
- arr.push(i)
- }
- return arr
- }
- console.log(range(1, 10))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement