import { anyToString } from '#src/utils/printers.js'; import { head, tail, nil, cons, isEmpty } from '#src/utils/list.functional.api.js'; let aList = cons(1, cons(2, nil)); console.log(anyToString(aList)); // -> (|1, 2|) console.logA(aList); // -> (|1, 2|) let anotherList = cons(3, tail(aList)); console.logA(anotherList) // -> (|3, 2|) ////////// Exercice 1 ////////// const aList = cons(1, cons(-1, cons(2, nil))); listMap((x) => x+1, aList); // -> (|2,0,3|) ////////// Exercice 2 ////////// ////////// Exercice 3 ////////// let aNumberList1 = cons(4, cons(9, cons(25, nil))); prodIterate(sqrt, aNumberList1); // -> 30 = sqrt(4) * sqrt(9) * sqrt(25) let aNumberList3 = cons(4, cons(9, cons(25, nil))); listMapFold(sqrt, aNumberList3); // -> (|2, 3, 4|) let aNumberList2 = cons(1, cons(8, cons(2, cons(7, nil)))); howMany((x) => x > 5, aNumberList2); // -> 2 ////////// Exercice 4 ////////// // Computes a string for the representation of the matrix `m` function matrixDisp(m) { return listFoldL((acc, el) => `${acc}\n ${el}`, "[", listMap(anyToString, m)) + "\n]\n"; } // An example of vector const aVector = cons(1, cons(2, cons(3, nil))); // (|1,2,3|) // An example of matrix const aLine1 = cons(1, cons(2, cons(3,nil))); // (|(|1,2,3|), const aLine2 = cons(4, cons(5, cons(6,nil))); // (|4,5,6|), const aLine3 = cons(7, cons(8, cons(9,nil))); // (|7,8,9|)|) const aMatrix = cons(aLine1, cons(aLine2, cons(aLine3, nil))); matrixDisp(aMatrix);