M8Test Help

reduceRightIndexed

val words = arrayOf("hello", "world", "kotlin") // 从右到左连接所有单词,并添加索引信息 val joinedString = words.reduceRightIndexed { index, word, acc -> acc + index + "_ " + word } // 输出:连接后的字符串: 2_kotlin 1_world 0_hello _console.log("连接后的字符串: ", joinedString)
def words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) // 从右到左连接所有单词,并添加索引信息 def joinedString = words.reduceRightIndexed { index, word, acc -> acc + index + "_ " + word } // 输出:连接后的字符串: 2_kotlin 1_world 0_hello $console.log("连接后的字符串: ", joinedString)
let words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) // 从右到左连接所有单词,并添加索引信息 let joinedString = words.reduceRightIndexed((index, word, acc) => acc + index + "_ " + word) // 输出:连接后的字符串: 2_kotlin 1_world 0_hello $console.log("连接后的字符串: ", joinedString)
local words = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.String"), "hello", "world", "kotlin")) -- 从右到左连接所有单词,并添加索引信息 local joinedString = words:reduceRightIndexed(function(index, word, acc) return acc .. index .. "_ " .. word end) -- 输出:连接后的字符串: 2_kotlin 1_world 0_hello _console:log("连接后的字符串: ", joinedString)
<?php $words = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.String"), "hello", "world", "kotlin")); // 从右到左连接所有单词,并添加索引信息 $joinedString = $words->reduceRightIndexed(function ($index, $word, $acc) { return $acc . $index . "_ " . $word; }); // 输出:连接后的字符串: 2_kotlin 1_world 0_hello $console->log("连接后的字符串: ", $joinedString);
words = _objectWrappers.wrap(_arrays.arrayOf(_plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) # 从右到左连接所有单词,并添加索引信息 joinedString = words.reduceRightIndexed(lambda index, word, acc: acc + str(index) + "_ " + word) # 输出:连接后的字符串: 2_kotlin 1_world 0_hello _console.log("连接后的字符串: ", joinedString)
# encoding: utf-8 words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) # 从右到左连接所有单词,并添加索引信息 joinedString = words.reduceRightIndexed { |index, word, acc| acc + index.to_s + "_ " + word } # 输出:连接后的字符串: 2_kotlin 1_world 0_hello $console.log("连接后的字符串: ", joinedString)
Last modified: 09 September 2025