Challenge 2 - Problem


#1

Hello,
I am having trouble to solve challenge Nr.2

Here is my idea:

I have two arrays. One with all the words and one with all the proper names. Now I want to compare these two lists and create a new array with only the words found in both arrays. This comparison should be case insensitive and therefor the third array would contain proper names and regular words that are spelled the same way. Then I want to create a fourth array by removing all the proper names from the list. As a result I would get an array that contains only regular words that could also be proper names if written with a capital first letter.

Problem:

I tried to create a new array with the method caseInsensitiveCompare but failed to create it.

  1. Try:
  1. Try:
  1. Try:

NSMutableArray *compare = [NSMutableArray array]; [compare addObject:[words caseInsensitiveCompare:names]];

I guessed that maybe the method caseInsensitiveCompare only works with strings so I tried:

Further tries:

Any ideas on how to create this third array or string?


#2

There are several ways to create arrays. For example:
Immutable arrays:

NSArray *A1 = [NSArray arrayWithObject:@"1"];
NSArray *A2 = [NSArray arrayWithObjects:@"1", @"two", @"3", @"Triple J", nil];
NSArray *A3 = [NSArray arrayWithArray:A2];
NSArray *A4 = [NSArray arrayWithObjects:A1, A2, A3, nil];
...

Mutable arrays:

NSMutableArray *A1 = [NSMutableArray array];
NSMutableArray *A2 = [NSMutableArray arrayWithObject:@"1"];
NSMutableArray *A3 = [NSMutableArray arrayWithObjects:@"1", @"two", @"3", @"Triple J", nil];
NSMutableArray *A4 = [NSMutableArray arrayWithObjects:A1, A2, A3, nil];

For further information, see: NSArray Class Reference and NSMutableArray Class Reference.

[quote]I tried to create a new array with the method caseInsensitiveCompare but failed to create it.

  1. Try:

NSArray *compare = [words caseInsensitiveCompare:names]; [/quote]
Why did this fail?

You can find out, by asking yourself these questions:

  • What kind of object words is?
  • Can I invoke the method caseInsensitiveCompare: on it?
  • If the answer is yes, what kind of object does the method caseInsensitiveCompare: return?

You can reason similarly for the other tries.


#3

Thank you.

I think my main problem is that I do not understand what kind of object the method caseInsensitiveCompare returns.