Test your knowledge of basic arrays and strings manipulation concepts with these easy, practical questions. Ideal for beginners looking to reinforce key programming skills in working with sequences and text data.
What is the result of getting the length of the array [5, 9, 2, 7]?
Explanation: The array [5, 9, 2, 7] contains four elements, so its length is 4. Choosing 3 would be counting one item less, and 5 would incorrectly assume an extra element. Option 7 is just one of the values in the array, not its length.
Given the string 'apple', what character is at index 2 if indexing starts at 0?
Explanation: Indexing starts at 0, so 'a' is at index 0, the first 'p' at index 1, and the second 'p' at index 2. 'a' would be index 0, 'l' at index 3, and 'e' at index 4. Only 'p' at index 2 is correct.
If colors = ['red', 'blue', 'green'], which value is returned by colors[1]?
Explanation: Array indices start at 0, so colors[1] refers to the second element, which is 'blue'. 'red' is the first element, 'green' is the third, and 'yellow' does not appear in the array.
What is the result of concatenating 'sun' and 'flower' without any separator?
Explanation: Concatenating two strings without a separator joins them directly, resulting in 'sunflower'. 'sun-flower' and 'sun flower' include extra characters that were not in the original strings. 'sunflower ' incorrectly includes an extra space at the end.
What is the reverse of the array [1, 2, 3]?
Explanation: Reversing [1, 2, 3] changes the order to [3, 2, 1]. The other options present jumbled or extended arrays that do not represent a correct reversal. Only [3, 2, 1] maintains all original elements in exact reverse order.
Does the word 'banana' contain the substring 'nan'?
Explanation: 'banana' does contain 'nan' starting at the second letter. 'No' and 'Maybe' are incorrect, as the substring is clearly present. 'None of the above' is invalid given that 'Yes' is the correct answer.
What is the smallest number in the array [7, 3, 5, 9]?
Explanation: Among the array elements, 3 is the lowest value. Choosing 5, 7, or 9 ignores the minimum value present. Checking each value ensures 3 is correct beyond reasonable doubt.
If you split the string 'cat,dog,mouse' by commas, how many elements will the resulting array have?
Explanation: Splitting by commas divides the string into ['cat', 'dog', 'mouse'], which is three parts. Two elements would miss an item, four is too many, and one implies no splitting occurred. Three is the correct count.
What is the string result of joining ['A', 'B', 'C'] with a hyphen as the separator?
Explanation: Joining with a hyphen places '-' between each letter, resulting in 'A-B-C'. 'ABC' has no separators, 'A, B, C' includes spaces and commas not specified, and 'A_B_C' uses underscores instead of hyphens.
Is the value 6 present in the array [4, 6, 8, 10]?
Explanation: The array [4, 6, 8, 10] clearly includes the value 6. 'No' is incorrect because it ignores the presence of 6. 'Not sure' and 'Sometimes' are not applicable, as the answer is clear from the array.