Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //problem solving (logic development)
- //competitive programming(?)
- //DSA
- //Data structure (how you should organize data to access and manipulate the data)
- //Algorithm
- //understand the problem (restate the problem in own words)
- // write down the details
- //Breakdown the problem (how many parts ?)
- //write down and Follow the steps
- //solve the steps
- //Finding the avg percentage
- //must pass(700)each subject
- //if failed any subject
- //should return 'F
- // if all subjects are passed, then return avg percentage
- //input array of numbers [990, 770, 760, 900, 700, 800]
- //output - percentage - 82
- // null (failed)
- // function avgPercentage(arr) {
- // //flag variable
- // let total = 0
- // let isPassed = true
- // //check each subject mark
- // //and if failed return null
- // for (let number of arr) {
- // if (number < 700) {
- // isPassed = false
- // }
- // }
- // if (!isPassed) return 'Failed'
- // // sum all number
- // for (let number of arr) {
- // total += number
- // }
- // // divide sum by element count
- // const avgNumber = total / arr.length
- // console.log(avgNumber)
- // // Divided by the 1000 and get the result
- // const fractionPercentage = avgNumber / 1000
- // console.log(fractionPercentage)
- // //multiply by 100 and return the result
- // return Math.round(fractionPercentage * 100)
- // }
- // console.log(avgPercentage([990, 770, 760, 900, 700, 800]))
- //get maximum number from an array
- // function getMax(arr) {
- //method way-1
- // let max_num = arr[0]
- // for(let num of arr){
- // if(num > max_num){
- // max_num = num
- // }
- // }
- //method way - 2
- // console.log(Math.max(...arr))
- // return Math.max.apply(null, arr)
- // const result = arr.reduce((maxNum, curr) => {
- // console.log(maxNum, curr)
- // return maxNum > curr ? maxNum : curr
- // })
- // console.log(result)
- // // console.log(max_num)
- // }
- // getMax([10, 14, 8, 12, 20, 1])
- // function getMin(arr){
- // let min_num = arr[0]
- // for(let num of arr){
- // if(num < min_num){
- // min_num = num
- // }
- // }
- // console.log(min_num)
- // }
- // getMin([10, 14, 8, 12, 20, 1])
- // function compareArray(arr1, arr2) {
- // if (arr1.length !== arr2.length) return false
- // for (let i = 0; i < arr1.length; i++) {
- // if (arr1[i] !== arr2[i]) {
- // return false
- // }
- // }
- // console.log(arr1.toString())
- // console.log(arr1.toString() === arr2.toString())
- }
- // console.log(compareArray([1, 2, 3, 5, 6], [1, 2, 3, 5, 6]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement