function solution(statues) {
let OutOfOrders = [];
let outOfOrderPos = 0;
let stillAscending;
// iterate through list elements and get the difference
let moreStatues = statues.map((statue, index) => {
if(index < statues.length - 1 ) {
if (statues[index + 1] - statue < 1){
if (outOfOrderPos === 0) {
outOfOrderPos = index + 1;
}
OutOfOrders.push(statue);
}
}
});
console.log(`outOfOrderPos: ${outOfOrderPos}`);
if(outOfOrderPos > 1 && outOfOrderPos < statues.length - 1) {
stillAscending = statues[outOfOrderPos + 1] - statues[outOfOrderPos - 1] >= 1;
} else {
stillAscending = true;
}
console.log(`OutOfOrders: ${OutOfOrders.length}`);
if (OutOfOrders.length < 2) {
return stillAscending;
}
return false;
}
console.log(solution([1,2,1,2]));
//fails because the outOfOrderPos is 5 but should be 4
// this happens when the outOfOrderPos - 1 digit is higher than sorrounding ones
// [1, 2, 3, 4, 99, 5, 6]
// [1, 2, 5, 3, 5] - same issue
//passes because numbers on either side of outOfOrderPos (3) are in incorrect order also
// [40, 50, 60, 10, 20, 30]
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.