JSFiddle - React, Tailwind, and code Playground

by Sebastian Kay

HTML

<button onclick="myFunction()">Try it</button>

JavaScript

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);

}