问答详情
源自:6-4 Scala reduceLeft与flodLeft

错误的值是怎么算的

val a = List(3,5,9) a.reduceLeft((x,y)=>(x+x))? =12 ? a.reduceLeft((x,y)=>(x+y))? =17 OK a.reduceLeft((x,y)=>(x+x+y))? =31 ?

提问者:cq_shijie 2016-07-14 10:52

个回答

  • 嘿喂狗_
    2016-07-15 01:57:21

    1. (3, 5) => 3+3 => 6 ,    (6, 9)=>6+6 => 12

    2. (3, 5) => 3+5 => 8 ,    (8, 9)=>8+9 => 17

    3. (3, 5) => 3+3+5 => 11 ,    (11, 9)=>11+11+9 => 31