Discuss / JavaScript / 作业

作业

Topic source

落叶起声

#1 Created at ... [Delete] [Delete and Lock User]

第一题:

来一手reduce函数 用length是否为0来判断是否为空

    function sum(...rest) {

            if (!rest.length) {

                return 0

            }

          return  rest.reduce((a, b) => {

                return a + b

            })

        }

第二题

    if(!pi) return 3.14 * r * r

    return pi * r * r

第三题

把换行去掉就好了


  • 1

Reply