CoDEVIANT #19 — If there’s a problem yo I’ll solve it
Check out the hook while my DJ revolves it!

If other devs are rappers, I’m Vanilla Ice.
function isMonotonic(array) {
let monoArr = []
array.forEach((el, i) => {
if(el > array[i + 1] ) {
monoArr.push('negative')
} else if(el < array[i + 1]) {
monoArr.push('positive')
}
})

monoArr = [... new Set(monoArr)]

if(monoArr.length == 1 || monoArr.length == 0) {
return true
} else {
return false
}
}
let monoArr = []
array.forEach((el, i) => {
if(el > array[i + 1]) {
monoArr.push('negative')
} else if(el < array[i + 1]) {
monoArr.push('positive')
}
})
I got $5 saying that fucker fell over at the end.
monoArr = [... new Set(monoArr)]
if(monoArr.length == 1 || monoArr.length == 0) {
return true
} else {
return false
}
Indubitably…bitch.
It’s a bird…it’s a plane…it’s a nerd from StackOverflow coming with answers and a side of condescension!
function isMonotonic(array) {
if(array.length <= 2) {
return true
}
let direction = array[1] - array[0]
for(let i = 2; i < array.length; i++){
if(direction === 0) {
direction = array[i] - array[i-1]
continue
}
if(breaksDirection(direction, array[i-1], array[i])){
return false
}
}
}
function breaksDirection(direction, previousInt, currentInt) {
const difference = currentInt - previousInt
if(direction > 0) {
return difference < 0
}
return difference > 0
}
if(array.length <= 2) {
return true
}
let direction = array[1] - array[0]
for(let i = 2; i < array.length; i++ ){
...
}
for(let i = 2; i < array.length; i++ ){
if(direction === 0) {
direction = array[i] - array[i - 1]
continue
}

...
}
for(let i = 2; i < array.length; i++ ){
if(direction === 0) {
direction = array[i] - array[i - 1]
continue
}
if(breaksDirection(direction, array[i-1], array[i])){
return false
}

}
function breaksDirection(direction, previousInt, currentInt) {
const difference = currentInt - previousInt
}
function breaksDirection(direction, previousInt, currentInt) {
const difference = currentInt - previousInt
if(direction > 0) {
return difference < 0
}
return difference > 0

}
return true
Right?
Me watching Netflix while ‘sleeping’

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adrian Rosales

Adrian Rosales

is a web developer, opera singer, actor, and lover of cats. (adrian-rosales.tech)