码迷,mamicode.com
首页 > 其他好文 > 详细

Day9 string.characters.count and closures

时间:2016-04-14 01:18:50      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

//                                      **Day9

//                                      CloseSure

 

var arr:[Int] = [1,2,3,4,5,9,8,7,6,0]

 

arr.sort()

 

func compareTwoInts(a:Int,b:Int) -> Bool

{

    return a>b

}

arr.sort(compareTwoInts)

 

// summary    sorted by the rules that the prefix at the head of high address  ,no matter > or <

 

 

 

var str :String = "tangyifan"

str.lengthOfBytesUsingEncoding(NSUTF8StringEncoding)

 

var strArr = ["a","bc","d","hijk","efg"]

strArr = strArr.sort({(s1:String,s2:String) -> Bool in

                if s1 != s2

                {

                    return s1 < s2

                }

                    return s1 > s2

    

            })

 

 

print("\(strArr)")

 

var arr1 = [0,3,2,1,5,6,8,7,6]

 

arr1 = arr1.sort()

 

arr1 = arr1.sort({(s1:Int,s2:Int) ->Bool in return s1 < s2})

 

print("\(arr1)")

 

arr1 = arr1.sort({s1,s2 -> Bool in return s1 > s2})

 

print("\(arr1)")

 

var stringArray = ["a","bc","m","d","ijklm","efg","a"]

 

stringArray = stringArray.sort({(s1:String,s2:String) -> Bool in

                   if s1.characters.count != s2.characters.count

                   {

                        return s1 < s2

                   }

                        return s1 > s2

                })

 

 

print("\(stringArray)")

 

 

func callnum (s1:Double , s2:Double) -> Bool

{

    return fabs(s1 - 5) > fabs(s2 - 5)

}

 

callnum(5, s2: 7)

 

callnum(0, s2: 1)

 

 

 

var numArray = ["2","3","1","8","7","9"]

 

numArray = numArray.sort({(s1,s2) -> Bool in

                            return s1 > s2

                        })

 

print("\(numArray)")

 

 

Day9 string.characters.count and closures

标签:

原文地址:http://www.cnblogs.com/tony0571/p/5389393.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!