Challenge your understanding of arrays and fundamental string manipulation concepts with this easy-level quiz featuring practical scenarios, common operations, and essential terminology. Perfect for learners seeking to strengthen their grasp of array structures, indexing, iteration, and basic string handling techniques.
In an array defined as [10, 15, 20, 25], which value is at index 2?
Explanation: The value at index 2 in a zero-based array is 20, because indexing starts at 0. The values at indexes 0 and 1 are 10 and 15 respectively. Option 25 is at index 3, and 10 is at index 0, making them incorrect choices.
If the string is 'apple', what is its length?
Explanation: The string 'apple' has 5 characters, so its length is 5. Option 4 would be correct if there were one less character. Option 6 and 8 are both too high for this simple word. Only '5' matches the correct character count.
What is the process of joining two arrays, such as [1, 2] and [3, 4], into one called?
Explanation: Merging is the process of combining two arrays into one larger array. Splitting is the opposite, which divides an array. Looping means iterating over elements, while sorting rearranges values. Only merging correctly describes joining arrays.
Which term describes joining the strings 'cat' and 'nap' to get 'catnap'?
Explanation: Concatenation means joining two strings end-to-end, forming 'catnap' from 'cat' and 'nap'. Reversing would flip character order, and shuffling rearranges them randomly. Slicing refers to extracting a part of the string, so 'concatenation' is the correct answer.
Given the array [5, 7, 9], how would you identify if the number 7 is present?
Explanation: To check if a value exists in an array, you search for it. Sorting changes order, slicing extracts a subarray, and merging combines arrays. Only searching is used for finding elements.
How do you change the second value in [18, 22, 35] to 30?
Explanation: The second value is at index 1 in a zero-based array. Index 0 changes the first value, index 2 alters the third, and index 3 is out of bounds. Therefore, you must replace the value at index 1.
What does splitting the string 'dog,cat,mouse' by the comma result in?
Explanation: Splitting by a comma divides the string into an array with three elements: 'dog', 'cat', and 'mouse'. A string of spaces would require replacing characters, not splitting. Reversing would flip the order of characters, and sorting needs an array, not a string.
What is it called when you take out the last item from an array?
Explanation: Popping removes the last element of an array. Appending adds to the end, prepending adds to the start, and shifting removes the first element. Only popping matches removing the last element.
Why can you not change the third letter of 'bird' directly?
Explanation: Strings are immutable, so their characters can't be changed in place. Flexible size isn't the issue; arrays can store other types, not just numbers, and characters can be accessed but not altered directly. Mutability is the key property limiting changes.
What is the length of the array ['x', 'y', 'z', 'a']?
Explanation: There are four elements in the array, so its length is 4. The answers '2' and '3' are less than the actual count, while 5 is greater. Only '4' matches the total number of elements.
For the string 'math', what is the character at index 2?
Explanation: Indexing starts at 0, so index 2 is the third character, which is 't'. 'm' is at index 0, 'a' is at index 1, and 'h' is at index 3. Only 't' matches.
Which operation combines ['red', 'blue'] into 'redblue'?
Explanation: Joining merges array elements into a single string. Splitting does the opposite, mapping changes items, and filtering removes some elements. Only joining results in 'redblue' from the original array.
If you slice [4, 6, 8, 10] from index 1 to 3 (excluding 3), what is the result?
Explanation: Slicing from index 1 up to, but not including, index 3 produces [6, 8]. [4, 6] includes the first element, and [6, 8, 10] goes beyond index 3. [8, 10] starts too late. Only [6, 8] matches the specified range.
Does 'basketball' contain the substring 'ball'?
Explanation: 'ball' is found within 'basketball' without any modifications. The string doesn't need to be changed or reversed. The only correct answer is 'Yes', as the substring clearly exists.
What do you call processing each value in an array one by one?
Explanation: Iterating means going through each element individually. Merging combines arrays, sorting changes their order, and concatenating joins either arrays or strings. Only iterating correctly matches the action described.
What is the result of converting 'Train' to lowercase?
Explanation: 'Train' in lowercase becomes 'train', with all letters small. 'TRAIN' uses all uppercase, 'Train' preserves the original case, and 'tRAIN' is incorrect. Only 'train' accurately shows the transformation.