473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Javascript help: arrays and a matrix

I'm in an introductory course, and my professor is not very good. I've been working on this problem, but as of now, I'm stuck. Essentially, we have to declare a matrix of grades and create a "Z" formation. Using the "Z" locations we have to average and print grades. Here are the parameters:

Declare an 8 x 8 matrix and an array of length 22.
(declare any other variable that you use in the algorithm)

1.- Populate the matrix.
2.- Copy the elements of the first row of the matrix, the anti-diagonal, and the last row of the matrix into the array.
(we call this in class the Z in the matrix)
3.- Sort the array.
4.- Assuming that the data in the arrays are grades, compute the average of the grades stored in the even locations of the array.
5.- Copy the array back into the matrix.(back into the Z)
6.- Print out the matrix values.

This is what I have so far:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Var k=0;
  3. Var j=0;
  4. Var i=0;
  5. Var x=0;
  6.  
  7. for (k=0;k<8;k++){
  8. x[j]=mat[i][k]
  9. j=j+1
  10. }
  11.  
  12. var x = new array (22);
  13. j=8;
  14. k=j;
  15. for(i=1;i<7;i++){
  16. k[j]mat[i][k];
  17. j=j+1;
  18. }
  19.  
  20. var mat=new array (8);
  21. i=7
  22. for(i=0;1<21;i=i+1){
  23. for(k=i+1;k<22;k=k+1){
  24. if(x[i]>x[k]){
  25. temp=x[i];
  26. x[i]=x
  27. x[k]=temp
  28. }
  29. }
  30. }
  31. x[i]=mat[i][k];
  32. mat[i][k]=x[j]
  33.  
  34.  
Nov 3 '11 #1

✓ answered by Dormilich

which part of the question belongs that code to? I can’t make any sense of what is written there.

1) is it up to you how to fill the matrix (random values, …) ?
2) Array.concat() comes in handy, but at least one for() loop will be required.
3) look up array sorting in your favourite reference work.
4) quite as simple as 3) as long as you know how to determine "even".
5) enter Array.splice(). essentially the reverse of 2).
6) there is a plethora of ways, depending on how it should look (optical & code-wise).

PS. I had averages between 3.7 and 4.9 (random values 0 to 9)
PPS. read up on array methods, they are really useful here.
PPPS. this hardest thing is to figure out, what to do in principle to achieve the tasks (i.e. programme logic), the coding itself is quite easy

3 2799
Dormilich
8,658 Expert Mod 8TB
which part of the question belongs that code to? I can’t make any sense of what is written there.

1) is it up to you how to fill the matrix (random values, …) ?
2) Array.concat() comes in handy, but at least one for() loop will be required.
3) look up array sorting in your favourite reference work.
4) quite as simple as 3) as long as you know how to determine "even".
5) enter Array.splice(). essentially the reverse of 2).
6) there is a plethora of ways, depending on how it should look (optical & code-wise).

PS. I had averages between 3.7 and 4.9 (random values 0 to 9)
PPS. read up on array methods, they are really useful here.
PPPS. this hardest thing is to figure out, what to do in principle to achieve the tasks (i.e. programme logic), the coding itself is quite easy
Nov 3 '11 #2
all of these are a great help, but as for number 4, no, i'm not sure how determine even numbers. suggestions?
Nov 3 '11 #3
Dormilich
8,658 Expert Mod 8TB
i'm not sure how determine even numbers.
how would you personally determine, whether a number is even? (like in Math course)
Nov 4 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Andy | last post by:
I'm not sure why my checkbox code is not working as per intended. It always keeps saying "Please select the department" even though I check the department... appreciate any help. <!DOCTYPE HTML...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
5
by: Budiman | last post by:
Hello friends, i need help for my assignment. For example i give input for a, b, c, d in matrix mode example like |a b| |c d| and i want to convert it to invers from that matrix, i hope...
4
by: fredy | last post by:
I Need javascript help to retrive the cpu information of client in mozilla browser Note: <script language="javascript"> alert(navigator.cpuClass); </script>
3
by: jor | last post by:
i want the key of a hash to be based on a variable: i tried: var c = 'blah'; var arr = { 'a':1000, b:2000, c.valueOf():3000 }; also var arr = { 'a':1000, b:2000, c.toString():3000 };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.