var elements, a elements = [10, 20, 30] a = MyArray.from(elements); println(a) println('reversed(): ' + a.reversed()); // elements: 10,20,30 // reversed(): elements: 30,20,10
var elements, a, fct elements = [10, 20, 30] a = MyArray.from(elements); fct = (elem) => 3 * elem println(a) println('map(fct): ' + a.map(fct)) // elements: 10,20,30 // map(fct): elements: 30,60,90
var elements, a elements = [10, 20, 30, 40] a = MyArray.from(elements) println(a) println('includes(30): ' + a.includes(30)) println('includes(35): ' + a.includes(35)) // elements: 10,20,30,40 // includes(30): true // includes(35): false
var elements, a, compareFct elements = [5, 10, 0, 10, 8, 3]; a = MyArray.from(elements); println(a); println('----') compareFct = elem => elem.equals(10) println('findClosestToEnd(compareFct for 10) (expecting 1)') println(a.findClosestToEnd(compareFct)) println('----') compareFct = elem => elem.equals(8) println('findClosestToEnd(compareFct for 8) (expecting 4)') println(a.findClosestToEnd(compareFct )) // elements: 5,10,0,10,8,3 // ---- // findClosestToEnd(compareFct for 10) (expecting 1) // 1 // ---- // findClosestToEnd(compareFct for 8) (expecting 4) // 4
var elements, a elements = [30, 10, 20, 30, 40] a = MyArray.from(elements); println(a) println('lastIndexOf(30): ' + a.lastIndexOf(30)); println('lastIndexOf(99): ' + a.lastIndexOf(99)); // elements: 30,10,20,30,40 // lastIndexOf(30): 3 // lastIndexOf(99): -1
var a, selectFct; a = new MyArray([10, 50, 10, 40, 50, 60, 10]); //filter (keep) all elements less or equal to 20 selectFct = anElem => anElem <= 20; println(a) println(a.filter(selectFct)) //select all elements greater than 100 //should result in empty array selectFct = anElem => anElem > 100 println('----') println(a) println(a.filter(select))
var a, rejectFct; a = new MyArray([10, 50, 10, 40, 50, 60, 10]); //reject all elements less or equal to 20 (keep others) rejectFct = anElem => anElem <= 20; println(a) println(a.filter(rejectFct)) //reject all elements greater than 100 (keep others) //should result in keeping all rejectFct = anElem => anElem > 100 println('----') println(a) println(a.filter(rejectFct))