emedinaa / kotlin-mvvm

MVVM(Model View ViewModel) sample in Kotlin using the components ViewModel, LiveData and Retrofit library
535 stars 117 forks source link

Zadachi #5

Closed YaKudryk closed 4 years ago

YaKudryk commented 4 years ago

Zadachi from Vova 1.txt

YaKudryk commented 4 years ago

import Foundation var someInts : [Int] someInts = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] someInts.shuffle()

func greet(accesing:Bool, intarray: [Int]) -> [Int] {
    var sorted:[Int]
    sorted=[]
    if !(intarray == nil) {  //waat i do if array nil? output empty array!   
        if !(intarray.isEmpty) {
         sorted = intarray.sorted()
            if !(accesing) {
              sorted = sorted.reversed()
            }
        }
    } 
    return sorted
}

print("Unsorted")
print(someInts) print("Sorted accesing")
print(greet(accesing:true, intarray:someInts)) print("Sorted deccesing")
print(greet(accesing:false, intarray:someInts))