



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
During the course work of Thinking Like Computers, we study the key concept of artificial intelligence. The main points in these lecture slides are:String Methods, Javascript Arrays, Separate Counters, Array of Counters, Dice Stats Page, Implementing Algorithms, Sequential Search, Binary Search, Index Variables, Writing Code, Swap List Elements
Typology: Slides
1 / 5
This page cannot be seen from the preview
Don't miss anything!
Lecture 22
Fall 2008
requires separate assignment statements for all 11 counters
requires a cascading if-else statement with 11 cases
not easily generalized – what if we wanted to use 8-sided dice?
the resulting code is shorter, simpler, and easier to generalize
function SeqSearch(list, desired) //// Assumes: listReturns: index is of an list array where desired of items first appears, // or -1 if not found { var index; index = 0; // START AT FIRST ITEM while (index < list.length ) { // AS LONG AS ITEMS LEFT if (list[index] = desired ) { // IF NEXT ITEM IS DESIRED ONE, return index; // THEN RETURN WHERE FOUND } index = index + 1; // GO ON TO NEXT ITEM } return -1; // IF FAILED TO FIND, RETURN - }
Any error?