**
let num = [12, 11, -22, 111, 2, 1, -02]
**
find just numbers
const num2 = num.filter((x) => typeof (x) === 'number')
console.log(num2)//12, 11, -22, 111, 2, 1, 2
reduce (sum)
const sum = num2.reduce((a, b) => a + b)
console.log(sum = ${sum}
) //113
every
const everyNum = num.every((a) => a > 2)
console.log(everyNum) //false ...all need true
some
const someNum = num.some((a) => a > 2)
console.log(someNum) //true...if any element true
lowestNum
const lowestNum = Math.min(...num2)
console.log(lowestNum) //-22
highestNum
const highest = Math.max(...num2)
console.log(highest) //111
evenNum
const evenNum = num2.filter((x) => x % 2 === 0)
console.log('even ' + evenNum) //12,-22,2,-2
oddNum
const oddNum = num2.filter((x) => x % 2 !== 0)
console.log('odd ' + oddNum) //11,111,1
compare
const compare = highest - lowestNum
console.log(compare) //133
sort
let numSort = [12, 11, -22, 111, 2, 1, -02]
const sort = numSort.sort((a, b) => a - b)
console.log(sort) // -22, -2, 1, 2, 11, 12, 'ss', 111
*sort *
let country = ['Bangladesh', 'India', 'Usa', 'Pakistan', 'Australia', 'Japan']
const sortCountry = country.sort()
console.log(sortCountry) //[ 'Australia', 'Bangladesh', 'India', 'Japan', 'Pakistan', 'Usa' ]
Top comments (0)