Tuesday, 24 July 2018

Numerical Operations On Arrays Using JavaScript

<html>
<head>
<h1> Numerical Operations On Arrays Using JavaScript</h1>
</head>
<body>
<button onclick="rev1()">Reverse</button>
<button onclick="sort1()">Sort</button>
<button onclick="highest()">Max Number</button>
<button onclick="Mini()">Min Number</button>
<script>

function rev1()
{

var n=0, i,j,a,r;
var arr1=[];

n=parseInt(prompt("Type how many numbers you would like to Reverse"));
document.write("Entered Value are : "+"<br/>");


    for(i=0;i<n;i++)
        {
          a=parseInt(prompt("Enter number " + (i+1)));
          arr1[i]=a;
          document.write(arr1[i]+ "<br/>");
        }
        document.write("After reversing the numbers"+"<br/>");   
        arr1.reverse();
        for(j=0;j<arr1.length;j++)
        {
                document.write(arr1[j]+"<br/>");
        }
       
}     
       
function sort1()
{

var n=0, i,j,a;
var arr1=[];

n=parseInt(prompt("Type how many numbers you would like to Sort"));
document.write("Entered Value are : "+"<br/>");


for(i=0;i<n;i++)
        {
          a=parseInt(prompt("Enter number " + (i+1)));
          arr1[i]=a;
          document.write(arr1[i]+ "<br/>");
        }
        document.write("After Sorting the numbers"+"<br/>");   
        arr1.sort();
        arr1.reverse();
        for(j=0;j<arr1.length;j++)
        {
                document.write(arr1[j]+"<br/>");
        }
       
}             
//Maximum number Function

function highest()
{

var n=0, i,j,a,r;
var arr1=[];

n=parseInt(prompt("Type how many numbers you would like to Enter"));
document.write("Entered Value are : "+"<br/>");


for(i=0;i<n;i++)
        {
          a=parseInt(prompt("Enter number " + (i+1)));
          arr1[i]=a;
          document.write(arr1[i]+ "<br/>");
        }
        document.write("Highest Number Entered is : "+"<br/>"); 
r=high1(arr1);
document.write(r);
       
}
function high1(arr2)      
{
        return Math.max.apply(null, arr2)
}     


//
function Mini()
{

var n=0, i,j,a,r1;
var arr1=[];

n=parseInt(prompt("Type how many numbers you would like to Enter"));
document.write("Entered Value are : "+"<br/>");


for(i=0;i<n;i++)
        {
          a=parseInt(prompt("Enter number " + (i+1)));
          arr1[i]=a;
          document.write(arr1[i]+ "<br/>");
        }
        document.write("Lowest Number Entered is : "+"<br/>"); 
r1=mini1(arr1);
document.write(r1);
       
}
function mini1(arr2)      
{
        return Math.min.apply(null, arr2)
}     


</script>
</body>

 </html>
Output:

Numerical Operations On Arrays Using JavaScript


   

1 comment:

  1. Python is an open-source, high level, interpreted programming language which offers great opportunities for object-oriented programming. Choosing a python training program from Red Prism Group, which is best training institute for python in noida.

    ReplyDelete

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...