Приглашаем посетить
Брюсов (bryusov.lit-info.ru)

Q&A

Previous Table of Contents Next

Q&A

Q1:

Can you suggest a quick way to find a particular string in an array element?

A1:

Iterating over the array and checking each element are the usual ways to do so. If you frequently find yourself searching an array to see whether an element is in the array, you probably didn't want to store the data in an array in the first place. A much more efficient structure for random-element access is a hash, which is covered in Hour 7.

Q2:

How can I eliminate duplicate elements from an array?

How can I count the number of unique elements in an array?

How can I see whether two arrays contain the same or different elements?

A2:

The answer to all these questions is the same: Use a hash. Hashes allow you to do some rather interesting manipulations on arrays quickly and efficiently. All these questions are answered in Hour 7.

    Previous Table of Contents Next