daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function matrix()
  2. {
  3.     var n = 5, m = 7;
  4.     var max = document.forma3.max.value;
  5.     var min = document.forma3.min.value;
  6.     function matrixArray(rows,columns){
  7.        var array = new Array();
  8.        for(var i=0; i<rows; i++){
  9.          array[i] = new Array();
  10.          for(var j=0; j<columns; j++){
  11.             array[i][j]= Math.floor(Math.random() * (max - min));
  12.             }
  13.         }
  14.     return array;
  15.     }
  16.    
  17.        
  18.     var myMatrix = matrixArray(n,m);
  19.     console.log(myMatrix.join('\n'));
  20.    
  21.     function sortMatrixArray(arr,rows,columns){
  22.        for(var i=0; i<rows; i++){
  23.          for(var j=0; j<=columns; j++){
  24.             if (arr[i][j] > arr[i+1][j])
  25.             {
  26.                 var k= arr[i][j];
  27.                 arr[i][j] = arr[i+1][j];
  28.                 arr[i+1][j] = k;
  29.             }
  30.         }
  31.     }
  32.     return arr;
  33. }
  34.    
  35.     var myNewMatrix = sortMatrixArray(myMatrix,n,m);
  36.     console.log(myNewMatrix.join('\n'));       
  37.  
  38.  
  39.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top