var delete_element = (function () {
function delete_element() { }
delete_element.prototype.element = function () {
var pos;
var c;
var n;
var value;
var array = [
100
];
n = parseInt(prompt("Enter number of elements in array"));
for(c = 0; c < n; c++) {
array[c] = parseInt(prompt("Enter " + n + " integers"));
}
for(var x = 0; x < n; x++) {
var span = document.createElement("span");
span.style.color = "Green";
span.innerText = "Enter " + x + " Element -> " + array[x] + "\n";
document.body.appendChild(span);
}
pos = parseInt(prompt("Enter the location where you wish to delete element"));
try {
if(pos >= n + 1) {
alert("Deletion not possible.");
} else {
for(c = pos - 1; c < n - 1; c++) {
array[c] = array[c + 1];
}
var span1 = document.createElement("span1");
span1.style.color = "red";
span1.innerText = "Resultant array is \n";
document.body.appendChild(span1);
for(c = 0; c <= n - 1; c++) {
var span = document.createElement("span");
span.style.color = "Blue";
span.innerText = "Array Element " + c + " -> " + array[c] + "\n";
document.body.appendChild(span);
}
}
} catch (Error) {
alert(Error.message);
}
};
return delete_element;
})();
window.onload = function () {
var greeter = new delete_element();
greeter.element();
}; |