Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Array helper methods
- //map
- //find
- //filter
- //findIndex
- //forEach
- //Reduce
- // const arr = [1, 2, 3, 4, 5, 6]
- // //extra step in default value
- // //acc-0 , curr-1 = 1
- // //acc - 1 , curr -2 = 3
- // //acc - 3, curr - 3 = 6
- // //acc- 6, curr- 4 = 10
- // //acc-10, curr-5 = 15
- // //acc-15, curr-6 = 21
- // const result = arr.reduce((acc, curr) => {
- // //logic
- // return acc + curr
- // }, 0)
- // console.log(result)
- //sum of even square
- // function sumOfEvenSquare(arr){
- // //filter the even value
- // // const filtered = arr.filter(num => num % 2 === 0)
- // // console.log(filtered)
- // // // squaring of the value
- // // const squarredArr = filtered.map(num => num ** 2)
- // // console.log(squarredArr)
- // // summation
- // // const result = squarredArr.reduce((acc, curr) => acc + curr )
- // // console.log(result)
- // const result = arr.filter((num) => num % 2 === 0).map((num) => num ** 2).reduce((acc, curr) => acc + curr)
- // return result
- // }
- // const arr = [ 2, 3, 4, 5, 6 ]
- // console.log(sumOfEvenSquare(arr))
- // Use the given array of product objects below, each with their name, price, and quantity sold. Additionally, you are given a tax rate as a percentage. Write a function called `calculateTotalSalesWithTax` that takes in an array of product objects, along with the tax rate (8%), and returns the total sales amount including tax.
- // const products = [
- // { name: 'Apple', price: 0.5, quantity: 10 },
- // { name: 'Banana', price: 0.3, quantity: 20 },
- // { name: 'Orange', price: 0.6, quantity: 15 },
- // ]
- // function calculateTotalSalesWithTax(products, taxRate) {
- // // calculate total product price
- // const totalPrice = products.reduce((acc, curr) => {
- // const price = acc + curr.price * curr.quantity
- // return price
- // }, 0)
- // console.log(totalPrice)
- // //calculate total Tax
- // const calulatedTax =( totalPrice * taxRate) / 100
- // console.log(calulatedTax)
- // //sum up the total price with tax
- // return totalPrice + calulatedTax
- // }
- // console.log(calculateTotalSalesWithTax(products, 8))
- // function findMissingLetter(arr) {
- // if (!Array.isArray(arr)) return ''
- // if (arr.length < 2) return ''
- // let start = arr[0].charCodeAt(0)
- // console.log(start)
- // const missingCharCode = arr.map((char) => char.charCodeAt(0))
- // console.log(missingCharCode)
- // const findMissingChar = missingCharCode.find((current) => {
- // console.log(current)
- // if (current - start > 1) {
- // return true
- // }
- // start = current
- // return false
- // })
- // console.log(findMissingChar)
- // const result =
- // missingCharCode.length >= 2 ? String.fromCharCode(findMissingChar - 1) : ''
- // return result
- // }
- function findMissingLetter(arr) {
- let start = arr[0].charCodeAt(0)
- console.log(start)
- const missingCharCode = arr.reduce((missing, char) => {
- const current = char.charCodeAt(0)
- if (current - start > 1 && missing == null) {
- missing = start + 1
- }
- start = current
- return missing
- }, null)
- console.log(missingCharCode)
- return missingCharCode ? String.fromCharCode(missingCharCode) : ''
- }
- findMissingLetter(['a', 'b', 'c', 'e', 'f'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement