// find elements
var array = []; //Global array
var d = ""; //String for easy access
var count = 0; //counter
//For some console log showed that fillArray() was not working as //intended
//running individually it works but it looks like there no value
//being passed
//the css and html does not seam to intrude as i tried this with
//pure javascript
//not really able to find a decent solution.
function fillArray() {
clearDisplay();
var size = parseInt(document.getElementById("location").value);
array = new Array(size);
for (var i = 0; i <= size; i++) {
array[i] = Math.floor(Math.random() * 100) + 1;
}
displayArray();
}
//----------------------------------
function clearDisplay() {
d = "";//clear the display with empty string
document.getElementById("output").innerHTML = "";
}
//-------------------------------------------------
function displayArray() {
for (var i = 0; i < array.length - 1; i++) {
d += i + ' : ' + array[i] + "<br/>";
}
document.getElementById("output").innerHTML = d;
}
//-----------------------------------------------------
function insertIntoArray(arr, index, num) {
var whatis = parseInt(document.getElementById("index").value);
var thisvalue = parseInt(document.getElementById("valuesss").value);
d = thisvalue + " inserted at location " + n + ".<br/>" + count + " Operations performed" + "<br/>";
for (i = length - 1; i < whatis; i--) {
count++;
array[i] = array[i - 1];
}
array[n] = thisvalue; {
count++;
} {
displayArray();
}
}
//-----------------------------------------------
function displaySearch(arr, value) {
clearDisplay();
var s = parseInt(document.getElementById("search").value);
var v = parseInt(document.getElementById("valuesss").value);
for (var i = 0; i < array.length; i++) {
count++;
if (array[i] == s) {
d = "In" + count + " operations" + s + "was not found";
} else {
d = s + "is at " + n + ". There were " + count + " operations...
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.