<small id='S4NdZ'></small><noframes id='S4NdZ'>

    <bdo id='S4NdZ'></bdo><ul id='S4NdZ'></ul>

    <i id='S4NdZ'><tr id='S4NdZ'><dt id='S4NdZ'><q id='S4NdZ'><span id='S4NdZ'><b id='S4NdZ'><form id='S4NdZ'><ins id='S4NdZ'></ins><ul id='S4NdZ'></ul><sub id='S4NdZ'></sub></form><legend id='S4NdZ'></legend><bdo id='S4NdZ'><pre id='S4NdZ'><center id='S4NdZ'></center></pre></bdo></b><th id='S4NdZ'></th></span></q></dt></tr></i><div id='S4NdZ'><tfoot id='S4NdZ'></tfoot><dl id='S4NdZ'><fieldset id='S4NdZ'></fieldset></dl></div>
    <legend id='S4NdZ'><style id='S4NdZ'><dir id='S4NdZ'><q id='S4NdZ'></q></dir></style></legend>

  1. <tfoot id='S4NdZ'></tfoot>
    1. 从 Bool 数组返回索引值数组,其中 true

      Return an array of index values from array of Bool where true(从 Bool 数组返回索引值数组,其中 true)
    2. <i id='XjLb2'><tr id='XjLb2'><dt id='XjLb2'><q id='XjLb2'><span id='XjLb2'><b id='XjLb2'><form id='XjLb2'><ins id='XjLb2'></ins><ul id='XjLb2'></ul><sub id='XjLb2'></sub></form><legend id='XjLb2'></legend><bdo id='XjLb2'><pre id='XjLb2'><center id='XjLb2'></center></pre></bdo></b><th id='XjLb2'></th></span></q></dt></tr></i><div id='XjLb2'><tfoot id='XjLb2'></tfoot><dl id='XjLb2'><fieldset id='XjLb2'></fieldset></dl></div>
    3. <small id='XjLb2'></small><noframes id='XjLb2'>

        <tfoot id='XjLb2'></tfoot>
          <tbody id='XjLb2'></tbody>

          • <bdo id='XjLb2'></bdo><ul id='XjLb2'></ul>

              1. <legend id='XjLb2'><style id='XjLb2'><dir id='XjLb2'><q id='XjLb2'></q></dir></style></legend>
                本文介绍了从 Bool 数组返回索引值数组,其中 true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                任何人都知道一种优雅的方法,可以从值为真的布尔数组中返回索引值数组.例如:

                Anyone know an elegant way to return an array of index values from an array of Bools where the values are true. E.g:

                let boolArray = [true, true, false, true]
                

                这应该返回:

                [0,1,3]
                

                推荐答案

                let boolArray = [true, true, false, true]
                let trueIdxs = boolArray.enumerate().flatMap { $1 ? $0 : nil }
                print(trueIdxs) // [0, 1, 3]
                

                或者(可能更具可读性)

                Alternatively (possibly more readable)

                let boolArray = [true, true, false, true]
                let trueIdxs = boolArray.enumerate().filter { $1 }.map { $0.0 }
                print(trueIdxs) // [0, 1, 3]
                

                这篇关于从 Bool 数组返回索引值数组,其中 true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)
                How to copy a quot;Dictionaryquot; in Swift?(如何复制“字典在斯威夫特?)
                Swift - How to mutate a struct object when iterating over it(Swift - 迭代结构对象时如何对其进行变异)
                How to copy text to clipboard/pasteboard with Swift(如何使用 Swift 将文本复制到剪贴板/粘贴板)
                Swift Cannot invoke #39;find#39; with an argument list of type #39;([Score], Score)#39; where Score is a struct(Swift 无法使用类型为“([Score],Score)的参数列表调用“find,其中 Score 是一个结构)
                How to load image asynchronously with Swift using UIImageViewExtension and preventing duplicate images or wrong Images loaded to cells(如何使用 UIImageViewExtension 与 Swift 异步加载图像并防止重复图像或错误图像加载到单元格) - IT屋-程序员软

                  <small id='svqua'></small><noframes id='svqua'>

                1. <legend id='svqua'><style id='svqua'><dir id='svqua'><q id='svqua'></q></dir></style></legend>
                    <tbody id='svqua'></tbody>

                  • <tfoot id='svqua'></tfoot>
                      <bdo id='svqua'></bdo><ul id='svqua'></ul>
                          <i id='svqua'><tr id='svqua'><dt id='svqua'><q id='svqua'><span id='svqua'><b id='svqua'><form id='svqua'><ins id='svqua'></ins><ul id='svqua'></ul><sub id='svqua'></sub></form><legend id='svqua'></legend><bdo id='svqua'><pre id='svqua'><center id='svqua'></center></pre></bdo></b><th id='svqua'></th></span></q></dt></tr></i><div id='svqua'><tfoot id='svqua'></tfoot><dl id='svqua'><fieldset id='svqua'></fieldset></dl></div>