Solution to S-99 ( P01 ~ P05 )

来源:互联网 发布:淘宝怎么提高浏览量 编辑:程序博客网 时间:2024/05/20 03:43
  def last(data: List[Any]): Any = {    if(data.size < 1)      throw new IllegalArgumentException("List is too short")    else      return data.last  }    def penultimate(data: List[Any]): Any = {    if(data.size < 2)      throw new IllegalArgumentException("List is too short")    else      return data(data.size-2);  }    def nth(index: Int, data: List[Any]): Any = {    if(data.size < index - 1)      throw new IllegalArgumentException("Index is out of Range")    else      return data(index)  }    def length(data: List[Any]): Int = {      return data.size  }    def reverse(data: List[Any]): List[Any] = {      return data.reverse  }

0 0
原创粉丝点击