// **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)")