Bootstrap

字符串倒序输出

原题是在Codewars上

要求是reverse(“Hello World”) == “World Hello” reverse(“Hi There.”) == “there. Hi”

#import <Foundation/Foundation.h>
NSString* reverse(NSString* text) {
    //字符串变成数据,根据引号里对象分离
    NSArray *words = [text componentsSeparatedByString:@" "];
    //数据倒序遍历,所有对象
    NSArray *reversed = [[words reverseObjectEnumerator] allObjects];
    //数组变成字符串,根据引号内对象隔开
    return [reversed componentsJoinedByString:@" "];
}

下面的是题目中

;