Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arrays II Robin Burke IT 130. Outline Homework #6 Portfolio Array review Array examples Array algorithms Multi-dimensional arrays.

Similar presentations


Presentation on theme: "Arrays II Robin Burke IT 130. Outline Homework #6 Portfolio Array review Array examples Array algorithms Multi-dimensional arrays."— Presentation transcript:

1 Arrays II Robin Burke IT 130

2 Outline Homework #6 Portfolio Array review Array examples Array algorithms Multi-dimensional arrays

3 Homework #6 Three component grades Knowledge Reasoning Communication Overall very good papers! Many nice site designs

4 Issues Target marketing not really possible for campaign web site you have to identify the audience that will use such a site not choose the audience and build site to suit Narrow content site has only policy positions and events easy to find these things real site would have much more Design justification report should justify design choices example: information hierarchy each page has foreground and background what belongs in each category what visual techniques distinguish

5 Portfolio Must include new copies of each homework exceptions if full credit, just copy homework #6 – report only  MS Word.doc or PDF file  no "original" needed Do not include labs homework #6 designs / notes Due date Midnight, 11/22 (Monday before Thanksgiving)

6 Portfolio Do Get started early you now have enough experience that early assignments should be easy (or at least easier) Aim for full credit on all assignments send me email if you don't understand the grading feedback Read the original assignment Don't Wait until the last minute Ignore what the grader had to say

7 Portfolio site it130 hwk1 hwk2...etc... portfolio index.html  points to old and new assignments hwk1 hwk2 hwk3...etc.. Example

8 Array Array is a list of values accessed by index name[index] foo[5] Must create before using foo = new Array (); Zero-based indexing length attribute arr.length

9 Using for loop to access array For loop pieces initial counter value: 0 exit test: value < array.length change to counter: + 1 Pattern for (i = 0; i < arr.length; i++) { do something to arr[i] element }

10 Images array twodice page from last week document.images[imgNo].src = "dice01.jpg"; How to read this from the document object the page get the images array a list of all the images on the page get one item from this array using imgNo as index some particular image set the src attribute of this image to the given value

11 Example n dice

12 Array algorithms Common tasks with arrays find an element with some property combine the elements of the array fill an array with values sort the elements

13 Combination example: average var total = 0; for (i = 0; i < numbers.length; i++) { total = total + numbers[i]; } ave = total / numbers.length;

14 Combination pattern Assume array contains some values var variable = empty value ; for (i = 0; i < array.length; i++) { variable = accumulate ( variable, array[i] ); }

15 Example build-sentence.html Assemble a sentence using the words in an array words = new Array ("welcome", "to", "arrays", "in", "JavaScript"); function result = "welcome to arrays in JavaScript"

16 Selection example Find the first element in the array less than zero for (i = 0; i < array.length; i++) { if (array[i] < 0) return i; } return -1;

17 Selection pattern for (i = 0; i < array.length; i++) { if ( test (array[i])) return i; or return array[i]; } return not found value ;

18 Selection Example Find the smallest element of an array A bit different from pattern We have to look at every element save the best so far

19 Fill example Fill an array with zeros for (i = 0; i < count; i++) { array[i] = 0; }

20 Fill pattern for (i = 0; i < size ; i++) { array[i] = initial value ; }

21 Example Alternate dice idea Fill array with image urls Pick from array instead of if statement Usually a good idea

22 Parallel arrays Sometimes we have data that is paired state / # of electoral votes homework / date due We can handle this with two arrays same size corresponding indices mean corresponding data

23 Example duedate.html

24 Problem Easy for arrays to get out of sync Two things to keep track of The pairing is in the programmer's head not represented in the structure of the data

25 Multi-dimensional array We can change our data structure instead of two arrays of elements, which are paired we can have one array of pairs Example

26 Homework #8 Slide show Add rewind, fast-forward, and back buttons Use enable / disable Write a function that controls the buttons so enable / disable logic is not repeated

27 Monday Data representation


Download ppt "Arrays II Robin Burke IT 130. Outline Homework #6 Portfolio Array review Array examples Array algorithms Multi-dimensional arrays."

Similar presentations


Ads by Google