Challenge 2!


#1

NSString *commonNamesString = [NSString stringWithContentsOfFile:@"/usr/share/dict/propernames" encoding:NSUTF8StringEncoding error:NULL];
NSString *wordsString = [NSString stringWithContentsOfFile:@"/usr/share/dict/words" encoding:NSUTF8StringEncoding error:NULL];

    NSArray *commonNamesArray = [commonNamesString componentsSeparatedByString:@"\n"];
    NSArray *wordsArray = [wordsString componentsSeparatedByString:@"\n"];
    NSMutableArray *results = [NSMutableArray array];
    
    for(NSString *name in commonNamesArray)
    {
        NSString *lowerName = [name lowercaseString];
        
        for(NSString *word in wordsArray)
        {
            if ([lowerName isEqualToString:word]) {
                [results addObject:name];
            }
            
        }
        
    }
    
    for(NSString *wordName in results)
    {
        NSLog(@"%@ is a word and a common name.", wordName);
    }