Skip to content

Instantly share code, notes, and snippets.

@Krafalski
Created January 6, 2017 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Krafalski/468bbba260f5c3af73704b1ac1099b72 to your computer and use it in GitHub Desktop.
Save Krafalski/468bbba260f5c3af73704b1ac1099b72 to your computer and use it in GitHub Desktop.
![ga](http://mobbook.generalassemb.ly/ga_cog.png)
# WDIR-MATRIX
---
Title: Two Dimensional Sums<br>
Type: Morning Exercise <br>
Duration: "0:45"<br>
Creator: Karolin Rafalski<br>
Course: WDIR-Matrix<br>
Competencies: Javascript functions<br>
Prerequisites: Javascript<br>
---
## Pair Programming
You will be pair-programming to solve today's morning exercise. Note that we will be doing this multiple times throughout the cohort, so you will all get a chance to be a driver and an observer. Embrace the position that you have in the moment.
<details><summary>Driver</summary>
You will be the person who is typing during this exercise. You should share your screen with your partner. Before you code anything, you should vocalize what you are doing and ask your partner for their opinion.
</details>
<details><summary>Observer / Passenger</summary>
You will be watching as your partner writes the code. It is your job to be vocal with your ideas, but you won't be dictating the code.
You should think about it at a higher level and ask things like "How would this piece of code handle this type of input?" and "What is this variable holding?" and "What are we outputting?", or "What are we trying to achieve with this line of code?"
</details>
<details><summary>Your Pairs</summary>
<table>
<th>Driver</th>
<th>Observer</th>
<tr>
<td>Blaine</td>
<td>Karolin</td>
</tr>
<tr>
<td>Kathryn</td>
<td>Shannon</td>
</tr>
<tr>
<td>Stephanie</td>
<td>Kaylie</td>
</tr>
<tr>
<td>Andy</td>
<td>Cameron</td>
</tr>
<tr>
<td>Jessica </td>
<td>Abi</td>
</tr>
</table>
</details>
### Loop the Loop: 2D Array Additon
**Make a function that returns the greatest sum of a row, column or diagonal from a two dimensional array**
Make a function that takes one argument, a two dimensional array, where all the arrays are the same length, and returns the greatest sum of the numbers by row, column and diagonal.
```
var arr = [ [10, 20, 30],
[40, 50, 60],
[70, -80, 90] ];
greatestSum(arr); //180
```
#### Hungry for More?
Test your function on this data set and let me know if it was a row, column or diagonal that had the greatest sum!
```
var bigArray =
[ [ 887, -541, -430, -590, 117, 172, -319, -18 ],
[ -269, 964, 209, 840, -456, 156, 365, -568 ],
[ 289, -41, 488, 198, 240, 124, -427, 214 ],
[ 452, 894, 968, -149, 683, 977, 741, -805 ],
[ 181, -714, -950, 107, 800, 751, -143, 380 ],
[ 152, 493, 707, 914, 37, 356, -625, 608 ],
[ -345, 906, 83, 676, 723, 381, 557, -183 ],
[ 199, -943, -710, 565, 193, 315, 281, 245 ] ];
```
**Still Hungry?**<br>
Create a function that takes one argument, an integer, that makes a 2D array of random integers between 0 and 1000 where the length of the rows and columns is determined by the argument.
Add a 30% chance that the integer will become negative.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment