Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //competitive programming (specializes in problem solving)
- //data structure , algorithm(steps of solving problem)
- //memory complexity, time complexity
- //logic development
- //=============================
- //Tools - hammer
- //problem - pin
- //problem solving
- // breakdown into small steps
- //receiving array
- //percentage 90/100 = 0.9
- // function getAvgPercentage(arr) {
- // //get total number after addition
- // //looping
- // let total = 0
- // for (let num of arr) {
- // // total = total + num
- // total += num
- // }
- // //average (total number/ count of element)
- // const avg = total / arr.length
- // //percentage
- // const percentage = avg / 100
- // return percentage
- // }
- // const result = getAvgPercentage([60, 70, 90, 50])
- // console.log(result)
- //get maximum number
- // receiving arr
- // function getMaxNum(arr) {
- //looping array
- //approach-1
- // let maxNum = arr[0]
- // for(let num of arr){
- // if(num > maxNum){
- // maxNum = num
- // }
- // }
- // console.log(maxNum)
- //approach - 2
- // console.log(Math.max(...arr))
- //approach-3
- // console.log(Math.max.apply(null, arr))
- // }
- // getMaxNum([1, 7, 9, 3, 10, 2])
- // function diffMaxMin(arr) {
- // //approach-1
- // let maxNum = arr[0]
- // for (let num of arr) {
- // if (num > maxNum) {
- // maxNum = num
- // }
- // }
- // let minNum = arr[0]
- // for (let number of arr) {
- // if (number < minNum) {
- // minNum = number
- // }
- // }
- // console.log(maxNum - minNum)
- // }
- // diffMaxMin([1, 7, 9, 3, 10, 2])
- //finding a element
- // function findElm(arr, searchElm) {
- // let isFound = false
- // for (let num of arr) {
- // console.log(num)
- // if (num === searchElm) {
- // isFound = true
- // break
- // }
- // }
- // return isFound
- // }
- // console.log(findElm([1, 7, 9, 3, 10, 2], 10))
- //return unique value based on searchArr
- // [1, 7, 9, 3]
- function excludeVal(arr, searchArr) {
- const unique = []
- //approach -1
- // for (let num1 of arr) {
- // let found = false
- // for (let num2 of searchArr) {
- // if(num1 === num2){
- // found = true
- // }
- // }
- // if(found == false){
- // unique.push(num1)
- // }
- // }
- //approach-2
- for (let number of arr) {
- if (!searchArr.includes(number)) {
- unique.push(number)
- }
- }
- console.log(unique)
- }
- console.log(excludeVal([1, 7, 9, 3, 10, 2], [10, 2]))
- console.log([1,2, 3].includes(10))
- //effect application performance n2
- for (let i = 0; i < 2; i++) {
- console.log(i) //2
- for (let z = 0; z < 2; z++) {
- console.log(z)
- ////4
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement