var cnt = 0;
// Put into a function for testing.
function foo() {
var array = [1, 3, 5, 6, 4,]
//var array = Array(5).fill().map(() => Math.floor((Math.random() * 6) + 1));
console.log("Array gegeben: " + array);
array.sort(function(a, b){return a-b});
console.log("Array sortiert: " + array)
var current = null;
for (var i = 0; i < array.length; i++) {
// Also need to make sure the next array item is a consecutive increase.
if (array[i] != current && array[i] === array[i-1] + 1) {
if (cnt > 4) {
return true;
}
current = array[i];
cnt++;
} else {
cnt = "ERROR";
}
}
if (cnt == "ERROR"){
for (var i = 1; i < array.length; i++) {
// Also need to make sure the next array item is a consecutive increase.
if (array[i] != current && array[i] === array[i-1] + 1) {
if (cnt > 4) {
return true;
}
current = array[i];
cnt++;
} else {
cnt = "ERROR";
}
}
}else{
cnt = 1;
}
if (cnt == 4) {
return "kleineStraße";
} else if (cnt == 5 || cnt == 6) {
return "kleineStraße und großeStraße";
} else {
return "ERROR KEINE STRAßE";
}
}
function myFunction() {
console.log(foo());
console.log("Count: " + cnt);
}
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.