let arrayOfNumbers = [1, 2, 3, 4, 5]
What would be the best way to compare the numbers against each other ?
For instance, comparing 1 to 2 then 2 to 3 then 3 to four, and so on ?
function t(a) {
let t = 0
for (let i = 0; i < a.length; i++) {
if (a[t] > a[t + 1]) {
console.log('down')
} else if (a[t] < a[t + 1]) {
console.log('up')
} else if (a[t] === a[t + 1]) {
console.log('no change')
}
t++
}
}
arrayOfNumbers [i] === arrayOfNumbers [i + 1]arrayOfNumbers [i + 1] === arrayOfNumbers [i + 2]arrayOfNumbers [i + n] === arrayOfNumbers [i + n + 1]you can use a for-loop