let a = MyArray.from([10, 20, 30, 40])
let a = MyArray.fromSize(10)
let array = MyArray.from([10, 20, 30, 40]) log('size: ' + array.size()) //size: 4
let array = MyArray.from([10, 20, 30, 40]) log(array.toString()) //elements: [10, 20, 30, 40]
let array = MyArray.from([10, 20, 30, 40]) log('get(0): ' + array.get(0)) //get(0): 10 log('get(2): ' + array.get(2)) //get(0): 30
let array = MyArray.from([10, 20, 30, 40]) array.set(1, 101) log(array.toString())) //elements: [10, 101, 30, 40] array.set(3, 999) log(array.toString())) //elements: [10, 101, 30, 999]
let a1 = MyArray.from([10, 20, 30]) let a2 = MyArray.from([10, 20, 30]) let a3 = MyArray.from([99, 20, 30]) log('Compare a1 and a2: ' + a1.equals(a2)) //Compare a1 and a2: true log('Compare a1 and a3: ' + a1.equals(a3)) //Compare a1 and a3: false
var elements, a elements = [10, 20, 30, 40] a = MyArray.from(elements); log(a) log('indexOf(30): ' + a.indexOf(30)); log('indexOf(99): ' + a.indexOf(99)); // elements: 10,20,30,40 // indexOf(30): 2 // indexOf(99): -1
var elements, a elements = [10, 20, 30] a = MyArray.from(elements); log(a) log('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 log(a) log('map(fct): ' + a.map(fct)) // elements: 10,20,30 // map(fct): elements: 30,60,90
var elements, a elements = [10, 20, 30] a = MyArray.from(elements) log(a) log('join("|"): ' + a.join("|")) // elements: 10,20,30 // join("|"): 10|20|30
var elements, a elements = [10, 20, 30, 40] a = MyArray.from(elements) log(a) log('includes(30): ' + a.includes(30)) log('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); log(a); log('----') compareFct = elem => elem.equals(10) log('findClosestToEnd(compareFct for 10) (execting 1)') log(a.findClosestToEnd(compareFct)) log('----') compareFct = elem => elem.equals(8) log('findClosestToEnd(compareFct for 8) (execting 4)') log(a.findClosestToEnd(compareFct )) // elements: 5,10,0,10,8,3 // ---- // findClosestToEnd(10) (execting 1) // 1 // ---- // findClosestToEnd(10) (execting 4) // 4
var elements, a elements = [30, 10, 20, 30, 40] a = MyArray.from(elements); log(a) log('lastIndexOf(30): ' + a.lastIndexOf(30)); log('lastIndexOf(99): ' + a.lastIndexOf(99)); // elements: 30,10,20,30,40 // lastIndexOf(30): 3 // lastIndexOf(99): -1
var a, searchFct a = new MyArray([10, 20, 30, 40, 50, 60, 70]) searchFct = anElem => anElem > 50 log(a.findIndex(searchFct)) // outputs 5 a = new MyArray([10, 50, 10, 40, 50, 60, 10]) searchFct = anElem => anElem == 50 log('----') log(a.findIndex(searchFct)) // outputs 1
var a, searchFct a = new MyArray([10, 20, 30, 40, 50, 60, 70]) searchFct = anElem => anElem < 50 log(a.findLastIndex(searchFct)) // outputs 3 a = new MyArray([10, 50, 10, 40, 50, 60, 10]) searchFct = anElem => anElem == 50 log('----') log(a.findLastIndex(searchFct)) // outputs 4
var a, count, matchFct a = new MyArray([10, 50, 10, 40, 50, 60, 10]) count = 0 //match if between 20 and 50 (inclusive) matchFct = anElem => anElem >= 20 && anElem <= 50 println(a) println('occurrences between 20 and 50 (inclusive)') println('occurrences(matchFct): ' + a.occurrences(matchFct));
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))