数组归一 reduce (数组归一) reduceRight(从右至左)

var addTwoNumbers = function(l1, l2) {
  var e =
    l1
      .reverse()
      .map((v, index, array) => v * Math.pow(10, array.length - index - 1))
      .reduce(function(prev, next) {
        return prev + next
      }) +
    l2
      .reverse()
      .map((v, index, array) => v * Math.pow(10, array.length - index - 1))
      .reduce(function(prev, next) {
        return prev + next
      }) +
    ''
  return e.split('').map(Number)
}

  

posted @ 2019-11-04 17:35  霜末之冬  阅读(265)  评论(0编辑  收藏  举报