CIS 111 Lecture Notes - Lecture 6: Salami

33 views2 pages
Chpts 12-14 (Strings, Arrays, RegExp) (Wk 5)
What we will cover in class
o Chpt 12: String Basics
o Chpt 14: Array Basics
Array Applications
Objects
o Set of Properties
Some are functions (methods)
//examples
Math.PI
Math.Random()
aeiou.legth
aeiou.charAt2
aeiou.charAt2toUpperCase
How Strings Are Represented in Memory
o Strings are arrays of characters
Use zero-based indexing
a
e
i
o
u
0
1
2
3
4
Processing a string? Use a ͞for͟ loop
o Access all characters in string by looping through index positions
Start of loop = 0 and end of loop will be determined by length of string
Length of string returned by length property
String Processing
o Count vowels
//recognizer for vowels
var isVowel=function(ch){
//https://www.kirupa.com/html5/the_devowelizer.htm
};
//count the vowels in a sentence
var countVowels=function(s){
//initialize a counter
var count=0;
//traverse string
for(var i=0; i<s.length; ++i){
if(isVowel(s.charAt(i)) //array subscript operator
++count;
}
return count;
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents

Related Questions