<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 問題 Problem 你有一個對象數組,你想將其簡化為一個值,與Ruby的`reduce()`和`reduceRight()`類似。 You have an array of objects and want to reduce them to a value, similar to Ruby’s?`reduce()`?and?`reduceRight()`. ## 問題 Solution 很簡單,你可以直接使用Array的`reduce()`和`reduceRight()`方法,傳遞一個匿名函數,保持代碼的整潔性和可讀性。化簡本身可能相當簡單,例如是用`+`操作符來連接數字或者字符串。 You can simply use Array’s?`reduce()`?and?`reduceRight()`methods along with an anonoymous function, keeping the code clean and readable. The reduction may be something simple such as using the?`+`?operator with numbers or strings. ~~~ [1,2,3,4].reduce (x,y) -> x + y # => 10 ~~~ ~~~ ["words", "of", "bunch", "A"].reduceRight (x, y) -> x + " " + y # => 'A bunch of words' ~~~ 或者,更復雜點,將一個列表中的對象聚集到一個聯合的對象中。 Or it may be something more complex such as aggregating elements from a list into a combined object. ~~~ people = { name: 'alec', age: 10 } { name: 'bert', age: 16 } { name: 'chad', age: 17 } people.reduce (x, y) -> x[y.name]= y.age x , {} # => { alec: 10, bert: 16, chad: 17 } ~~~ ## 討論 Discussion JavaScript在1.8版中加入了`reduce`和`reduceRight`方法。CoffeeScript提供了一種簡單但很自然的方法表達匿名函數。在這個把一系列的項合并到一個結果的問題中非常漂亮地結合到了一起。 Javascript introduced?`reduce`?and?`reduceRight`?in version 1.8\. Coffeescript provides a natural and simple way to express anonymous functions. Both go together cleanly in the problem of merging a collection’s items into a combined result.
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看