M8Test Help

filter

val numbers = arrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // 筛选出所有偶数 val evenNumbers = numbers.filter { it % 2 == 0 } // 输出:偶数: [2, 4, 6, 8, 10] _console.log("偶数: ", evenNumbers) val words = arrayOf("hello", "world", "kotlin", "android") // 筛选出长度大于 5 的单词 val longWords = words.filter { it.count() > 5 } // 输出:长度大于 5 的单词: [kotlin, android] _console.log("长度大于 5 的单词: ", longWords)
def numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) // 筛选出所有偶数 def evenNumbers = numbers.filter { it % 2 == 0 } // 输出:偶数: [2, 4, 6, 8, 10] $console.log("偶数: ", evenNumbers) def words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin", "android")) // 筛选出长度大于 5 的单词 def longWords = words.filter { $objectWrappers.wrap(it).count() > 5 } // 输出:长度大于 5 的单词: [kotlin, android] $console.log("长度大于 5 的单词: ", longWords)
let numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Integer"), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) // 筛选出所有偶数 let evenNumbers = numbers.filter((it) => { return it % 2 == 0 }) // 输出:偶数: [2, 4, 6, 8, 10] $console.log("偶数: ", evenNumbers) let words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin", "android")) // 筛选出长度大于 5 的单词 let longWords = words.filter((it) => $objectWrappers.wrap(it).count() > 5) // 输出:长度大于 5 的单词: [kotlin, android] $console.log("长度大于 5 的单词: ", longWords)
local numbers = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.Integer"), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) -- 筛选出所有偶数 local evenNumbers = numbers:filter(function(it) return it % 2 == 0 end) -- 输出:偶数: [2, 4, 6, 8, 10] _console:log("偶数: ", evenNumbers) local words = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.String"), "hello", "world", "kotlin", "android")) -- 筛选出长度大于 5 的单词 local longWords = words:filter(function(it) return _objectWrappers:wrap(it):count() > 5 end) -- 输出:长度大于 5 的单词: [kotlin, android] _console:log("长度大于 5 的单词: ", longWords)
<?php $numbers = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.Long"), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); // 筛选出所有偶数 $evenNumbers = $numbers->filter(function ($it) { return $it % 2 == 0; }); // 输出:偶数: [2, 4, 6, 8, 10] $console->log("偶数: ", $evenNumbers); $words = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.String"), "hello", "world", "kotlin", "android")); // 筛选出长度大于 5 的单词 $longWords = $words->filter(function ($it) use ($objectWrappers) { return $objectWrappers->wrap($it)->count() > 5; }); // 输出:长度大于 5 的单词: [kotlin, android] $console->log("长度大于 5 的单词: ", $longWords);
numbers = _objectWrappers.wrap(_arrays.arrayOf(_plugins.loadClass("java.lang.Long"), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) # 筛选出所有偶数 evenNumbers = numbers.filter(lambda it: it % 2 == 0) # 输出:偶数: [2, 4, 6, 8, 10] _console.log("偶数: ", evenNumbers) words = _objectWrappers.wrap( _arrays.arrayOf(_plugins.loadClass("java.lang.String"), "hello", "world", "kotlin", "android")) # 筛选出长度大于 5 的单词 longWords = words.filter(lambda it: _objectWrappers.wrap(it).count() > 5) # 输出:长度大于 5 的单词: [kotlin, android] _console.log("长度大于 5 的单词: ", longWords)
# encoding: utf-8 numbers = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.Long"), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) # 筛选出所有偶数 evenNumbers = numbers.filter { |it| it % 2 == 0 } # 输出:偶数: [2, 4, 6, 8, 10] $console.log("偶数: ", evenNumbers) words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin", "android")) # 筛选出长度大于 5 的单词 longWords = words.filter { |it| $objectWrappers.wrap(it).count() > 5 } # 输出:长度大于 5 的单词: [kotlin, android] $console.log("长度大于 5 的单词: ", longWords)
Last modified: 08 August 2025