SHARE
TWEET

Untitled

a guest Feb 20th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import scala.math.abs
  2. // 気温リスト1~12月
  3. val temperatureSeq:Seq[Int] =
  4.   Seq(4, 5, 11, 17, 19, 22, 28, 28, 22, 19, 14, 7)
  5. def diffTemperature2(tSeq: Seq[Int]) = {
  6.   tSeq.sliding(2).foldLeft(Seq.empty[Int])((totalSeq, numSeq) =>
  7.     totalSeq :+ abs(numSeq.head - numSeq.last)
  8.   )
  9. }
  10. diffTemperature2(temperatureSeq)
  11. // -> res0: Seq[Int] = List(1, 6, 6, 2, 3, 6, 0, 6, 3, 5, 7)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top