Lost numbers week challenge

PHOTO EMBED

Fri Oct 28 2022 06:50:03 GMT+0000 (Coordinated Universal Time)

Saved by @ericggDev #kotlin

/*
 * Enunciado: Dado un array de enteros ordenado y sin repetidos, 
 * crea una función que calcule y retorne todos los que faltan entre
 * el mayor y el menor.
 */

val originalList = listOf(1,2,7,8)
fun main() {
   val newList = findLostNumbers(originalList)
    print(newList)
}

fun findLostNumbers(originalList:List<Int>):ArrayList<Int>{
    val newList = ArrayList<Int>()
    for (i in originalList.first()..originalList.last()) {
        if(!originalList.contains(i))
        {
           newList.add(i) 
        }
    }
    return newList
}
content_copyCOPY