



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




components are identifiable via indices , or numbers that correspond to the order in which individual characters occur in a string indices are assigned in ascending order from left to right, so that the first character in the string is at index 0
it takes an index as an input and returns the character at that particular index
word = "foo"; ch = word.charAt(0); // ASSIGNS ch = "f"
it takes a character or string as input and returns the index at which the character or string first occurs (or -1 if not found) str = "banana"; num1 = str.search("n"); // ASSIGNS num1 = 2 since the character // "n" first occurs at index 2 num2 = str.search("ana"); // ASSIGNS num2 = 1 since the string // "ana" first occurs at index 1 num3 = str.search("z"); // ASSIGNS num3 = -1 since the character // "z" does not occur anywhere
nth Æ nthway apple Æ appleway
banana Æ ananabay cherry Æ errychay
the assignment misc[0] = 1000 would store the value 1000 as the first item in the array, overwriting the value that was previously there
recall the Pig Latin page we might want to generalize the page so that it translates entire phrases instead of just words that is, the user would enter an arbitrary sequence of words and each word would be translated this task would be very difficult using our current set of programming tools
user = "Grace Murray Hopper"; arr1 = user.split(" "); // ASSIGNS arr1 to be the array // ["Grace", "Murray", "Hopper"]
RAM – Random Access Memory GUI – Graphical User Interface WWW – World Wide Web
the Acronym function takes a phrase, such as "What you see is what you get", splits it into an array of individual words, then extracts the first letters to construct the acronym
use the split function to separate out the individual numbers then, traverse the resulting array and calculate the sum and average of the numbers