遍歷數組提取List[Int]
1 def toFlatMap(input:List[Any],result:List[Int]):List[Int]=input match{ 2 case h::t=>h match {case e:Int=>toFlatMap(t,e::result) 3 case x:List[Any] => toFlatMap(t,toFlatMap(x,result)) 4 case _=>toFlatMap(t,result)} 5 case Nil=>result6 case _=> result 7 } 8 9 val myList=List("a",List("a,",1000,2000),11,2,3,4,"abc",5,List(6,List(100,200),2,1).reverse,"a")10 11 print(toFlatMap(myList,List[Int]()).reverse)
遍歷數組提取List[Int]
相關推薦
遍歷數組提取List[Int]
ges spa clas blog cnblogs atm -1 tof reverse 1 def toFlatMap(input:List[Any],result:List[Int]):List[Int]=input match{ 2 case h::t=&g
總結for循環及for循環增強遍歷數組,list,set和map
循環 string 沒有 htable str arr val aaa entry 一.對於集合 (1)普通for循環 int[] arr = { 2, 1, 2 }; for(int i=0;i<arr.length;i++){
叠代器遍歷數組
println 叠代 iterator ring import port super() out rri public class Student { String name; int age; public String getName() { return n
利用React遍歷數組,並且用數組的元素生成<li>arrItem</li>標簽組
fun cti rri get 並且 reac numbers arr func var numbers = [1,2,3,4,5,6,7,8,9]; ReactDom.render({ <ul> { numbers.map(functi
foreach遍歷數組、數組的轉置與方陣的跡
ray n) length nbsp copy 數組方法 封裝 -s 調用方法 1 public class Copy1 { 2 3 public static void main(String[] args) { 4 array1()
php遍歷數組賦值
php pre 遍歷 each val core light int amp <?php $arr=array( array("num"=>100,"name"=>"Liuxy","score"=>"hello")
php-foreach遍歷數組
this span array arr argument foreach 指定 json div 做微信開發中遇到用json轉碼過來的數組,需要用foreach遍歷出指定字段的數據,結果老是提示Invalid argument supplied for foreach錯誤
easyui 兩種for 循環遍歷數組
eas dex cti 循環 easyui ++ bsp row yui 方法一: //rowArray 數組 for(var i=0;i<rowArray.length;i++){ var rowObj = rowArray[i]; }
遍歷數組 foreach
col 輸出 ati code array [] clas reac ++ package com.java.array; public class Myforeach { public static void main(String[] ARGS){
PHP中遍歷數組有三種常用的方法
log jin 存儲 方法 執行 ron () ech ++ 在PHP中操作最多的數據估計也就是數組了,有著效率高、速度快、存儲方便的特點。 PHP中遍歷數組有三種常用的方法:1、for循環,用法最為靈活,靈活到懷疑人生,但記住格式也非常簡單。2、foreach,是PHP為
for循環使用range遍歷數組嘗試修改元素值的問題
() for循環使用 例子 range 失敗 嘗試 參數 定義函數 出現 在Golang語言中,將一個數組名作為參數傳給一個函數,背後的操作是產生一個該數組的副本,在函數中對這個數組副本做的操作都不會影響原數組本身。比如下面這個例子 package main imp
JDK5的新特性之增強for循環遍歷數組或集合
color 類型 -s 遍歷 blog class lec for循環 遍歷數組 【格式】 1 for(元素的類型 變量名 : 數組或Collection集合名){ 2 //此處使用變量名即可,該變量就是普通for裏的i。 3 }
java遍歷數組並重新拼接數組裏的元素
IT inf light OS detail 拆分 lac infer AC public ArrayList getinferfacelist(ArrayList<TaskNameList> taskNameLists) { String
Jquery 遍歷數組之$().each方法與$.each()方法介紹
gre 一個 var 頁面 his alert index blog .cn $().each() 對於這個方法,在dom處理上用的比較多,如果一個html頁面上面有多個checkbox,這時用$().each來處理checkbox是比較不錯的; $("input[typ
js對比for、forEach、map遍歷數組速度
.get bsp 數組 console col star index -s reac p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 19.0px Consolas; color: #6b82d9 } p.p2 { margin:
遍歷數組
div ole 生成函數 es5 ons AR item map code 7.0 for-of :遍歷復雜數據類型 7.0.1 ES5——for-in 遍歷數組 主要用於遍歷JSON對象 let arr = [‘a‘,‘b‘,‘c‘,‘d‘]; for(let i i
js遍歷數組重復值和數組中對象重復值
arr 字符 函數 for UNC res {} 預覽 indexof() 數組去除重復值: arr.indexOf() 方法返回某個指定字符串值再字符中首次出現的位置, 如果數組中沒有則返回-1 var arr=[2,8,5,0,5,2,6,7,2]; function
JavaScript中遍歷數組,最好不要用for...in
標準 .com key javascrip 是我 ring 表示 技術分享 就是 先看一段代碼 var arr = [2,3,4,5]; for(var i = 0; i < arr.length; i++){ console.log(i
JQ 的class類的操作 效果 遍歷 內置遍歷數組的函數 事件
pla ngs sed event out sun get 祖先 time class類的操作: 向指定元素添加相應類名: <!DOCTYPE html> <html> <head> <meta chars
遍歷數組的方法
color reac first col 功能 .so some each foreach 1、forEach 1 let arr = [‘first‘,‘second‘]; 2 arr.forEach((val,index)=>{console.log(index