是否可以使用更高阶的javascript函数将一维数组的大小调整为多维数组(即1x6到2x3),还是必须解决for循环?
您有任何代码示例将[0,1,2,3,4,5]
调整为[[0,1,2],[3,4,5]]
?
答案 0 :(得分:1)
对于真正的2D数组,您可以将其展平并使用生成器通过使用新数组的映射获取值。
List<BlockEntry> blockList = new ArrayList<BlockEntry>();
File parent = new File(System.getProperty("java.io.tmpdir"));
File temp = new File(parent, "sample-file.txt");
String blockText="hellow world";
if (temp.exists()) {
temp.delete();
}
try {
temp.createNewFile();
CloudBlockBlob blob = container.getBlockBlobReference(temp.getName());
blob.uploadFromFile(temp.getAbsolutePath());
//Add Block to the created blob
String blockId1 = Base64.encode("B1".getBytes());
InputStream inputStream1 = new ByteArrayInputStream(blockText.getBytes());
long len = -1;
BlockEntry block1 = new BlockEntry(blockId1);
blockList.add(block1);
blockBlob.uploadBlock(blockId1, inputStream1, len);
blockBlob.commitBlockList(blockList);
//Print the blob content
System.out.println("Printing the block content" + blob.downloadText());
} catch (IOException ex) {
ex.printStackTrace();
}
答案 1 :(得分:-1)
使用Ramda https://ramdajs.com/docs/#splitEvery
ContextMiddleware