有沒有辦法編寫這種拾取/映射操作edges = edges.map(([v1, v2]) => [vertices[v1], vertices[v2]]);// exampleconst edges = [ [0, 1], [1, 0]];const vertices = [ [0, 0], [1, 1]]; ~~~>[ [ [0, 0], [1, 1] ], [ [1, 1], [0, 0] ]]更優雅,也許使用lodash?我迄今為止最好的解決方案是這樣的:function pickMap(edges, vertices) { return ld.invokeMap(edges, "map", ld.propertyOf(vertices));}但也許我錯過了一些更基本的程序。就像是edges.map(([v1, v2]) => ld.pick(vertices, [v1, v2]))很接近,但它返回一個帶有錯誤鍵 (v1, v2) 而不是 (0, 1) 的對象數組。
選取地圖/使用 Lodash 進行深度選取
素胚勾勒不出你
2023-12-14 14:35:07