├── .breakpoints ├── .gitignore ├── .replit ├── 1p ├── 1series │ ├── 0 │ │ └── triangularES6.js │ └── 2do │ │ └── 1.1series-problems.js ├── 2complexity │ ├── 0 │ │ └── gcd-iterative.js │ └── 2do │ │ └── 1.2complexity-problems.js ├── 3vector │ ├── 0 │ │ └── arraysMethods4stu.js │ ├── 2do │ │ └── 1.3ds-problems.js │ └── zeeAlso │ │ └── forOf4stu.js ├── 4sorting │ ├── 0 │ │ └── inversions.js │ ├── 2do │ │ └── 1.4sorting-problems.js │ └── zeeAlso │ │ └── array-not.js ├── 5searching │ └── 2do │ │ └── 1.5searching-problems.js └── 6ds │ ├── 0 │ └── attach4stu.js │ ├── 2do │ └── 1.6ds-problems.js │ └── zeeAlso │ ├── map4stu.js │ ├── object-add.js │ └── set4stu.js ├── 2p ├── 1stack │ ├── 0loose │ │ └── stack-loose.js │ ├── 2do │ │ ├── 2p-practice-stack-sorting-solution.js │ │ └── 2p-practice-stack-sorting.js │ ├── 5es │ │ └── mcm14stack.js │ ├── 6es │ │ └── Stack6es4stu.js │ └── zeeAlso │ │ └── stack6es4stu.js ├── 2queue │ ├── 0loose │ │ └── queue-loose.js │ ├── 2do │ │ ├── 2.4queue-problems.js │ │ ├── 2.4queue-solution.js │ │ ├── 2p-practice-queue-sorting-solution.js │ │ └── 2p-practice-queue-sorting.js │ ├── 5es │ │ ├── mcm14queue-in.js │ │ └── mcm14queue-out.js │ └── 6es │ │ └── queue6es4stu.js ├── 3linked │ ├── 1 │ │ ├── 2do │ │ │ ├── 1.1linked-problems.js │ │ │ └── 1.1linked-solution.js │ │ ├── Node4stu5es.js │ │ ├── list4stu.js │ │ └── traverse.js │ ├── 0bj │ │ ├── 2do │ │ │ └── 1.0linkedlist-problems-not.js │ │ ├── linked-loose+.js │ │ └── linked-loose.js │ ├── 5es │ │ ├── linked5es.js │ │ └── useLinked5es.js │ ├── 6es │ │ └── Linked6es4stu.js │ ├── 8imports │ │ ├── 2do │ │ │ ├── useNode-problem.js │ │ │ └── useNode-solution.js │ │ └── useNode.js │ └── zeeAlso │ │ ├── circularList4stu.js │ │ ├── dcircular4stu.js │ │ ├── doublyList4stu.js │ │ ├── queue5es4stu.js │ │ ├── sortedList4stu.js │ │ ├── stack5es4stu.js │ │ └── unsortedList4stu.js └── 6ds │ ├── 1sorting │ ├── 2do │ │ └── 2.1sorting-problems.js │ └── zeeAlso │ │ └── runs.js │ └── 5matrix │ ├── 0 │ └── matrix4stu.js │ ├── 2do │ └── 5.0problems2do.js │ └── zeeAlso │ └── matrixForOf4stu.js ├── 3p ├── 1recursive │ ├── 0 │ │ ├── countDownIter.js │ │ └── countDownRec.js │ └── 2do │ │ └── 2.0problems.js ├── 2trees │ ├── 1linked │ │ ├── 0 │ │ │ ├── 0tree-object.js │ │ │ └── traverse.js │ │ ├── 1 │ │ │ ├── 1tree.js │ │ │ ├── 2do │ │ │ │ └── problem.js │ │ │ └── preorder.js │ │ └── 2 │ │ │ ├── 2do │ │ │ └── 2.2tree-problems.js │ │ │ └── together.js │ ├── 2do │ │ ├── problem2do1.js │ │ └── problem2do2.js │ └── array2do │ │ └── 2do.js └── 3graphs │ ├── 1array- │ ├── 0 │ │ └── graph.js │ ├── 1 │ │ ├── graph-array.js │ │ ├── graph-ds.js │ │ ├── graph-linked.js │ │ ├── graph-map.js │ │ ├── graph-obj.js │ │ └── graph-set.js │ ├── 5 │ │ └── 2do │ │ │ ├── 5.1incidence1.js │ │ │ ├── 5.1incidence2.js │ │ │ └── 5.1incidence3.js │ ├── 2do │ │ └── 3.1weighted2do.js │ ├── 4useGraph │ │ └── useGraph-m-sample.js │ └── zeeAlso │ │ ├── corEtal09pp611di.js │ │ ├── corEtal09pp611un.js │ │ └── tree-vs-graph.js │ ├── 2do │ ├── problem2do1.js │ └── problem2do2.js │ └── linked2do │ └── 2do.js ├── README.md ├── docs ├── 0.md ├── 1.1series.md ├── 1.2complexity.md ├── 1.3vector.md ├── 1.4sorting.md ├── 1.5searching.md ├── 1.6ds.md ├── 2.1sorting.md ├── 2.2lrecursive.md ├── 2.3stack.md ├── 2.4queue.md ├── 2.5matrix.md ├── 2.6ds.md ├── 3.1linkedlist.md ├── 3.2tree.md ├── 3.3graph.md └── 3.4ds.md ├── index.js ├── jrgp ├── graph │ ├── Graph-m-sample.js │ ├── Graph-m-util.js │ ├── Graph-m.js │ ├── graph2do1.js │ ├── graph2do2.js │ ├── graph2do3.js │ ├── graph2do4.js │ ├── graph2do5.js │ ├── graph2do6.js │ ├── graph5es.js │ └── graph6es.js ├── linked │ ├── node.js │ ├── node5es.js │ └── node6es.js ├── math.js ├── matrix │ ├── Matrix.js │ └── Matrix2do.js ├── o │ ├── 2do │ │ ├── coin500.js │ │ ├── dice1.js │ │ └── dice500.js │ └── coin1.js ├── queue │ └── 2do.js ├── random │ └── 2do.js ├── series │ └── 2do.js ├── sort │ └── 2do.js ├── stack │ └── 2do.js ├── tree │ ├── tree5es.js │ └── tree6es.js ├── useMath.js ├── util │ └── 2do.js ├── vector │ └── 2do.js ├── z_dp │ └── 2do.js ├── z_hash │ └── 2do.js └── z_string │ └── 2do.js ├── newBranch.txt ├── package-lock.json ├── package.json └── replit.nix /.breakpoints: -------------------------------------------------------------------------------- 1 | { 2 | "files": {} 3 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vscode/ 3 | ._* 4 | .DS_Store 5 | .Spotlight-V100 6 | .Trashes 7 | /**/node/ 8 | /**/node_modules/ 9 | -------------------------------------------------------------------------------- /.replit: -------------------------------------------------------------------------------- 1 | entrypoint = "index.js" 2 | 3 | hidden = [".config"] 4 | 5 | [interpreter] 6 | command = [ 7 | "prybar-nodejs", 8 | "-q", 9 | "--ps1", 10 | "\u0001\u001b[33m\u0002\u0001\u001b[00m\u0002 ", 11 | "-i" 12 | ] 13 | 14 | [[hints]] 15 | regex = "Error \\[ERR_REQUIRE_ESM\\]" 16 | message = "We see that you are using require(...) inside your code. We currently do not support this syntax. Please use 'import' instead when using external modules. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)" 17 | 18 | [nix] 19 | channel = "stable-22_05" 20 | 21 | [env] 22 | XDG_CONFIG_HOME = "/home/runner/.config" 23 | PATH = "/home/runner/$REPL_SLUG/.config/npm/node_global/bin:/home/runner/$REPL_SLUG/node_modules/.bin" 24 | npm_config_prefix = "/home/runner/$REPL_SLUG/.config/npm/node_global" 25 | 26 | [gitHubImport] 27 | requiredFiles = [".replit", "replit.nix", ".config"] 28 | 29 | [packager] 30 | language = "nodejs" 31 | 32 | [packager.features] 33 | packageSearch = true 34 | guessImports = true 35 | enabledForHosting = false 36 | 37 | [unitTest] 38 | language = "nodejs" 39 | 40 | [debugger] 41 | support = true 42 | 43 | [debugger.interactive] 44 | transport = "localhost:0" 45 | startCommand = [ "dap-node" ] 46 | 47 | [debugger.interactive.initializeMessage] 48 | command = "initialize" 49 | type = "request" 50 | 51 | [debugger.interactive.initializeMessage.arguments] 52 | clientID = "replit" 53 | clientName = "replit.com" 54 | columnsStartAt1 = true 55 | linesStartAt1 = true 56 | locale = "en-us" 57 | pathFormat = "path" 58 | supportsInvalidatedEvent = true 59 | supportsProgressReporting = true 60 | supportsRunInTerminalRequest = true 61 | supportsVariablePaging = true 62 | supportsVariableType = true 63 | 64 | [debugger.interactive.launchMessage] 65 | command = "launch" 66 | type = "request" 67 | 68 | [debugger.interactive.launchMessage.arguments] 69 | args = [] 70 | console = "externalTerminal" 71 | cwd = "." 72 | environment = [] 73 | pauseForSourceMap = false 74 | program = "./index.js" 75 | request = "launch" 76 | sourceMaps = true 77 | stopOnEntry = false 78 | type = "pwa-node" 79 | 80 | [languages] 81 | 82 | [languages.javascript] 83 | pattern = "**/{*.js,*.jsx,*.ts,*.tsx}" 84 | 85 | [languages.javascript.languageServer] 86 | start = "typescript-language-server --stdio" 87 | -------------------------------------------------------------------------------- /1p/1series/0/triangularES6.js: -------------------------------------------------------------------------------- 1 | // 2 | // tringular numbers 3 | // 4 | 5 | let fn = n => { 6 | for(let s=1,k=1; k input, preconditions, arguments 15 | // <- output, postconditions, result 16 | 17 | 18 | 19 | // 20 | // exercises 21 | // 22 | 23 | 24 | 25 | //1. Fibonacci 26 | // fibonacci(n) 27 | // -> n integer 28 | // <- the n first fibonacci elements 29 | 30 | //2. Powers of 2 31 | // power2(n) 32 | // -> n integer 33 | // <- the n first elements of 2^n 34 | 35 | -------------------------------------------------------------------------------- /1p/2complexity/0/gcd-iterative.js: -------------------------------------------------------------------------------- 1 | // 2 | // gcd - greatest common divisor 3 | // also known as Euclid's algorithm 4 | // 5 | const gcd=(a, b) => { 6 | let u = a 7 | let v = b 8 | let r = 0 9 | while (u > 0) { 10 | if (u < v) { 11 | r = u 12 | u = v 13 | v = r 14 | } 15 | u -= v 16 | } 17 | console.log('print here how many steps it took') 18 | return v 19 | } 20 | 21 | console.time('it took') 22 | console.log('gcd(1, 1e3) =',gcd(1, 1000000))//1 23 | console.log('print here how much time it took') 24 | console.timeEnd('it took') 25 | 26 | //then try 27 | //console.log(gcd(3, 2)) 28 | //console.log(gcd(1000000005, 999999999)) 29 | //can we do better ? (yes/no) 30 | -------------------------------------------------------------------------------- /1p/2complexity/2do/1.2complexity-problems.js: -------------------------------------------------------------------------------- 1 | // 2 | // create one file by program 3 | // implement a method, function, non-function solution 4 | // solve each as requested 5 | // 6 | // COMPLEXITY 7 | 8 | //1. sieve of Eratosthenes 9 | // sieve(n) 10 | // -> n integer 11 | // <- the n first elements 12 | 13 | //2. random number 14 | // random(n) 15 | // -> n integer 16 | // <- one random number in [1-n] 17 | -------------------------------------------------------------------------------- /1p/3vector/0/arraysMethods4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // what it does : one by one 3 | // 4 | 5 | let numbers = [ 3, 2, 1] 6 | console.log(numbers) 7 | 8 | // 9 | numbers.push(10, 11) 10 | console.log(numbers) 11 | 12 | // 13 | numbers.pop() 14 | console.log(numbers) 15 | 16 | //vs pop 17 | numbers.shift() 18 | console.log(numbers) 19 | 20 | //vs push 21 | numbers.unshift( -2, -1, 0) 22 | console.log(numbers) 23 | 24 | //remove/separate/splice 25 | let ns = numbers.splice(2,3) 26 | console.log(numbers) 27 | console.log(ns) 28 | 29 | //extract 30 | let sl = numbers.slice(2) 31 | console.log(numbers) 32 | console.log(sl) 33 | -------------------------------------------------------------------------------- /1p/3vector/2do/1.3ds-problems.js: -------------------------------------------------------------------------------- 1 | /** INSTRUCTIONS 2 | * 3 | * create one file by program 4 | * implement a method, function, non-function solution 5 | * solve each as requested 6 | * may use code from previous exercises 7 | * 8 | * PROBLEM 1 9 | * insertAt(p,v) 10 | * 11 | * inserts a value v, at position p, in the array 12 | * @arg {number} p - position 13 | * @arg {number} v - value 14 | * 15 | * @example 16 | * insertAt(3,3) 17 | * Verify operation result by outputing the array before and after 18 | * 19 | * PROBLEM 2 20 | * removeAt(p) 21 | * 22 | * removes value at position p 23 | * @arg {number} p - position 24 | * 25 | * @example 26 | * removeAt(3) 27 | * 28 | * @see {@link https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array} 29 | * @see {@link https://jsdoc.app} 30 | */ 31 | -------------------------------------------------------------------------------- /1p/3vector/zeeAlso/forOf4stu.js: -------------------------------------------------------------------------------- 1 | let anArray = [2, -3, 4, -5, 6] 2 | 3 | for (let x of anArray) { 4 | console.log(x) 5 | } 6 | -------------------------------------------------------------------------------- /1p/4sorting/0/inversions.js: -------------------------------------------------------------------------------- 1 | // for the array to be sorted: 2 | // how many inversion are needed 3 | // which ones 4 | 5 | let inversions= A => { 6 | nInv = 0 7 | 8 | for(i = 1; i A[j]){ 11 | nInv = nInv + 1 12 | } 13 | return nInv 14 | } 15 | 16 | let a=[1,3,5,2,4,6] 17 | console.log(inversions(a)) -------------------------------------------------------------------------------- /1p/4sorting/2do/1.4sorting-problems.js: -------------------------------------------------------------------------------- 1 | // 2 | // create one file by program 3 | // implement a method, function, non-function solution 4 | // solve each as requested 5 | // may use code from previous exercises 6 | // 7 | // SORTING 8 | 9 | 10 | //1. bubblesort 11 | // sort(d) 12 | // -> d an array of random numbers 13 | // <- the random numbers sorted 14 | 15 | //2. selectionsort 16 | // sort(d) 17 | // -> d an array of random numbers 18 | // <- the random numbers sorted 19 | 20 | // forEach 21 | // + verify is sorted 22 | // 23 | // + print 24 | // - time it took 25 | // - steps it tooks 26 | -------------------------------------------------------------------------------- /1p/4sorting/zeeAlso/array-not.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | let nums = [3,-2,-1] 6 | 7 | console.log(nums) 8 | 9 | console.log(nums.sort())//not sorted 10 | -------------------------------------------------------------------------------- /1p/5searching/2do/1.5searching-problems.js: -------------------------------------------------------------------------------- 1 | // 2 | // pending 3 | // 4 | -------------------------------------------------------------------------------- /1p/6ds/0/attach4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // attach - as a push wrapper 3 | // 4 | 5 | let a = [3,2,1] 6 | const fn = (k) => a.push(k) 7 | 8 | console.log(a) 9 | fn(4) 10 | a 11 | -------------------------------------------------------------------------------- /1p/6ds/2do/1.6ds-problems.js: -------------------------------------------------------------------------------- 1 | // 2 | // create one file by program 3 | // implement a method, function, non-function solution 4 | // solve each as requested 5 | // may use code from previous exercises 6 | // 7 | 8 | // 1. DS-obj 9 | // a. produce 1e5 random names, ie name35927 10 | // b. add each random name into our ds-obj 11 | // c. measure the time it took 12 | // d. calculate the average of 7 runs 13 | 14 | // 2. Map 15 | // a. produce 1e5 random names, ie name35927 16 | // b. add each random name into a Map 17 | // c. measure the time it took 18 | // d. calculate the average of 7 runs 19 | -------------------------------------------------------------------------------- /1p/6ds/zeeAlso/map4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | const map = new Map() 6 | .set(1, 'a1') 7 | .set(2, 'b1') 8 | 9 | map 10 | -------------------------------------------------------------------------------- /1p/6ds/zeeAlso/object-add.js: -------------------------------------------------------------------------------- 1 | // 2 | // objects 3 | // 4 | 5 | let obj = {} 6 | 7 | //add key-value 8 | obj["firstName"] = "JRG" 9 | obj["lastName"] = "Pulido" 10 | //vs 11 | //obj.firstName = "JRG" 12 | //obj.lastName = "Pulido" 13 | 14 | //get 15 | obj[0]//undefined 16 | obj["firstName"] 17 | //vs 18 | //obj.firstName 19 | -------------------------------------------------------------------------------- /1p/6ds/zeeAlso/set4stu.js: -------------------------------------------------------------------------------- 1 | //const mySet = new Set() 2 | 3 | const mySet = new Set(['ORDERED',"some", "unique", "unique", "unique", "values", 'UNSORTED']) 4 | mySet 5 | -------------------------------------------------------------------------------- /2p/1stack/0loose/stack-loose.js: -------------------------------------------------------------------------------- 1 | // 2 | // loose code 3 | // vs 4 | // asClass code 5 | // 6 | 7 | console.log('Hello stack DS world in ES6+\n') 8 | 9 | let a=[] 10 | 11 | a.push('a') 12 | console.log(a) 13 | 14 | a.push('b') 15 | console.log(a) 16 | 17 | a.push('d') 18 | console.log(a) 19 | 20 | a.forEach(k=>console.log(k)) 21 | 22 | a.pop() 23 | console.log(a) 24 | 25 | a.pop() 26 | console.log(a) 27 | console.log(a.length) 28 | 29 | a.pop() 30 | console.log(a) 31 | console.log(a.length) 32 | -------------------------------------------------------------------------------- /2p/1stack/2do/2p-practice-stack-sorting-solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * your solution here 4 | * 5 | */ 6 | -------------------------------------------------------------------------------- /2p/1stack/2do/2p-practice-stack-sorting.js: -------------------------------------------------------------------------------- 1 | /** INSTRUCTIONS 2 | * 3 | * create one file by program 4 | * implement a method, function, non-function solution 5 | * solve each as requested 6 | * may use code from previous exercises 7 | * 8 | * PROBLEM 1 9 | * Using a array-based implementation 10 | * stack-sorting 11 | * 12 | */ 13 | -------------------------------------------------------------------------------- /2p/1stack/5es/mcm14stack.js: -------------------------------------------------------------------------------- 1 | // 2 | // ES5 3 | // from the book mcm14 4 | // 5 | 6 | function Stack() { 7 | this.dataStore = [] 8 | this.top = 0 9 | this.push = push 10 | this.pop = pop 11 | this.peek = peek 12 | this.clear = clear 13 | this.length = length 14 | } 15 | 16 | function push(element) { 17 | this.dataStore[this.top++] = element 18 | } 19 | 20 | function peek() { 21 | return this.dataStore[this.top-1] 22 | } 23 | 24 | function pop() { 25 | return this.dataStore[--this.top] 26 | } 27 | 28 | function clear() { 29 | this.top = 0 30 | } 31 | 32 | function length() { 33 | return this.top 34 | } 35 | 36 | let s = new Stack() 37 | s.push("David")//0 38 | s.push("Raymond")//1 39 | s.push("Bryan")//2 40 | console.log("length: " + s.length()) 41 | console.log(s.peek()) 42 | 43 | 44 | 45 | let popped = s.pop() 46 | console.log("The popped element is: " + popped) 47 | console.log(s.peek()) 48 | 49 | 50 | 51 | s.push("Cynthia") 52 | console.log(s.peek()) 53 | 54 | 55 | s.clear() 56 | console.log("length: " + s.length()) 57 | console.log(s.peek()) 58 | s.push("Clayton") 59 | console.log(s.peek()) 60 | -------------------------------------------------------------------------------- /2p/1stack/6es/Stack6es4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // ES6 stack class design 3 | // 4 | // zeeAlso 5 | // stack6es4stu 6 | // mcm14stack 7 | // 8 | 9 | class Stack { 10 | //creates stack 11 | //constructor(){} 12 | 13 | //pushes the item on stack 14 | push(o){}//add, put, insert, enter, append, set, store 'o' 15 | 16 | //returns the top item without popping it from stack 17 | peek(){}//top: <- 'o', not remove 18 | 19 | //returns the last item pushed and removes it from stack 20 | pop(){}//get, delete, remove, leave, access 21 | 22 | //returns True if stack has no pushed items 23 | isEmpty(){}//<-boolean 24 | //returns True if stack is full, depending on the DS 25 | isFull(){}//<-boolean 26 | 27 | search(k){}//looks4 'k',<- 'o' 28 | size(){}//length, count 29 | traverse(){}//visit, list, print 30 | 31 | toString(){} 32 | makeEmpty(){}//clear 33 | } 34 | -------------------------------------------------------------------------------- /2p/1stack/zeeAlso/stack6es4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // ES6 3 | // to complete 4 | // 5 | 6 | class Stack { 7 | constructor(){ 8 | this.data = [] 9 | this.top = 5//stack size 10 | } 11 | 12 | push(o){//validate stack not full 13 | if (this.isFull()) 14 | console.log('full stack') 15 | else{ 16 | this.data.push(o) 17 | console.log(o,'added') 18 | } 19 | } 20 | 21 | peek(){ 22 | return this.data[this.data.length-1] 23 | } 24 | 25 | pop(){//validate stack not empty 26 | if (this.isEmpty()) 27 | console.log('empty stack') 28 | else 29 | console.log(this.data.pop(),'popped') 30 | } 31 | 32 | isEmpty(){ 33 | if (this.data.length === 0)//this.size() 34 | return true 35 | else 36 | return false 37 | } 38 | 39 | isFull(){ 40 | if (this.data.length === this.top) 41 | return true 42 | else 43 | return false 44 | } 45 | 46 | size(){ 47 | return this.data.length 48 | } 49 | 50 | search(k){} 51 | traverse(){} 52 | 53 | toString(){} 54 | makeEmpty(){ 55 | this.data = [] 56 | } 57 | } 58 | 59 | let s = new Stack() 60 | s.push(4) 61 | s.push(0) 62 | s.push(3) 63 | s.push(2) 64 | s.push(1) 65 | s.push(5) 66 | //s.search(5) 67 | console.log('size',s.size()) 68 | 69 | console.log(s.peek()) 70 | s.pop() 71 | s.pop() 72 | s.pop() 73 | s.pop() 74 | s.pop() 75 | console.log('size',s.size()) 76 | s.pop() 77 | -------------------------------------------------------------------------------- /2p/2queue/0loose/queue-loose.js: -------------------------------------------------------------------------------- 1 | // 2 | // loose code 3 | // vs 4 | // asClass code 5 | // 6 | 7 | let Q=new Array() 8 | 9 | Q.unshift('A')//enqueue 10 | Q.unshift('B') 11 | Q.unshift('C') 12 | // vs 13 | // push 14 | 15 | console.log(Q.pop())//dequeue 16 | console.log(Q.pop()) 17 | console.log(Q.pop()) 18 | // vs 19 | // shift 20 | -------------------------------------------------------------------------------- /2p/2queue/2do/2.4queue-problems.js: -------------------------------------------------------------------------------- 1 | /** INSTRUCTIONS 2 | * 3 | * create one file by program 4 | * implement a method, function, non-function solution 5 | * solve each as requested 6 | * may use code from previous exercises 7 | * 8 | * PROBLEM 1 9 | * Queue implementation (array-based) 10 | * 11 | * add 12 | * property 13 | * top=5 14 | * 15 | * methods 16 | * isFull() 17 | * isEmpty() 18 | * 19 | */ 20 | -------------------------------------------------------------------------------- /2p/2queue/2do/2.4queue-solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * your solution here 4 | * 5 | */ 6 | -------------------------------------------------------------------------------- /2p/2queue/2do/2p-practice-queue-sorting-solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * your solution here 4 | * 5 | */ 6 | -------------------------------------------------------------------------------- /2p/2queue/2do/2p-practice-queue-sorting.js: -------------------------------------------------------------------------------- 1 | /** INSTRUCTIONS 2 | * 3 | * create one file by program 4 | * implement a method, function, non-function solution 5 | * solve each as requested 6 | * may use code from previous exercises 7 | * 8 | * PROBLEM 1 9 | * Using a array-based implementation 10 | * queue-sorting 11 | * 12 | */ 13 | -------------------------------------------------------------------------------- /2p/2queue/5es/mcm14queue-in.js: -------------------------------------------------------------------------------- 1 | // 2 | // ES5 3 | // to complete 4 | // 5 | 6 | function Queue() { 7 | this.dataStore = [] 8 | 9 | this.enqueue= function(element) { 10 | this.dataStore.push(element) 11 | } 12 | 13 | this.dequeue= function() { 14 | return this.dataStore.shift() 15 | } 16 | 17 | this.front= function() { 18 | return this.dataStore[0] 19 | } 20 | 21 | this.back= function() { 22 | return this.dataStore[this.dataStore.length-1] 23 | } 24 | 25 | this.toString= function() { 26 | let retStr = "" 27 | for (let i = 0; i < this.dataStore.length; ++i) { 28 | retStr += this.dataStore[i] + "\n" 29 | } 30 | return retStr 31 | } 32 | 33 | this.empty= function() { 34 | if (this.dataStore.length == 0) 35 | return true 36 | else 37 | return false 38 | 39 | } 40 | 41 | this.full= function() {} 42 | } 43 | 44 | 45 | // 46 | // test program 47 | // 48 | let q = new Queue() 49 | q.enqueue("Meredith") 50 | q.enqueue("Cynthia") 51 | q.enqueue("Jennifer") 52 | 53 | console.log(q.toString()) 54 | 55 | console.log("Front of queue: " + q.front()) 56 | console.log("Back of queue: " + q.back()) 57 | 58 | q.dequeue() 59 | console.log(q.toString()) 60 | console.log('done') 61 | -------------------------------------------------------------------------------- /2p/2queue/5es/mcm14queue-out.js: -------------------------------------------------------------------------------- 1 | // 2 | // ES5 3 | // 4 | 5 | function Queue() { 6 | this.dataStore = [] 7 | this.enqueue = enqueue 8 | this.dequeue = dequeue 9 | this.front = front 10 | this.back = back 11 | this.toString = toString 12 | this.empty = empty 13 | } 14 | 15 | 16 | function enqueue(element) { 17 | this.dataStore.push(element) 18 | } 19 | 20 | function dequeue() { 21 | return this.dataStore.shift() 22 | } 23 | 24 | function front() { 25 | return this.dataStore[0] 26 | } 27 | 28 | function back() { 29 | return this.dataStore[this.dataStore.length-1] 30 | } 31 | 32 | function toString() { 33 | let retStr = "" 34 | for (let i = 0; i < this.dataStore.length; ++i) { 35 | retStr += this.dataStore[i] + "\n" 36 | } 37 | return retStr 38 | } 39 | 40 | function empty() { 41 | if (this.dataStore.length == 0) { 42 | return true 43 | } 44 | else { 45 | return false 46 | } 47 | } 48 | 49 | function full() {} 50 | 51 | 52 | 53 | // 54 | // test program 55 | // 56 | let q = new Queue() 57 | q.enqueue("Meredith") 58 | q.enqueue("Cynthia") 59 | q.enqueue("Jennifer") 60 | 61 | console.log(q.toString()) 62 | 63 | console.log("Front of queue: " + q.front()) 64 | console.log("Back of queue: " + q.back()) 65 | 66 | q.dequeue() 67 | console.log(q.toString()) 68 | console.log('done') 69 | -------------------------------------------------------------------------------- /2p/2queue/6es/queue6es4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // todo 3 | // 4 | 5 | class Queue {// constructor(){}//creates queue 6 | 7 | //enqueues the item on the queue 8 | enqueue(o){}//add, put, insert, enter, append, set: 'o' 9 | 10 | //returns the first item enqueued and removes it from queue 11 | dequeue(){}//get, delete, remove, leave 12 | 13 | //returns the front item without dequeueing the item 14 | front(){}//head: <- 'o' 15 | 16 | //returns the rear item without dequeueing the item 17 | back(){}//rear: <- 'o' 18 | 19 | //returns True if queue has not enqueued items 20 | isEmpty(){}//<-boolean 21 | //returns True if queue if full, depending on the DS 22 | isFull(){}//<-boolean 23 | 24 | search(k){}//looks4 'k',<- 'o' 25 | size(){}//length, count 26 | traverse(){}//visit 27 | 28 | makeEmpty(){}//clear 29 | toString(){}//print 30 | } 31 | 32 | let q1 = new Queue() 33 | q1.isFull() 34 | -------------------------------------------------------------------------------- /2p/3linked/0bj/2do/1.0linkedlist-problems-not.js: -------------------------------------------------------------------------------- 1 | /** the PROBLEM with arrays 2 | * 3 | * for instance, create 100,000, then: 4 | * insert a new element at position 3 5 | * remove element at position 4 6 | * think about the number of operations that have to be carried out 7 | * 8 | * this section has NOT exercises 9 | */ 10 | -------------------------------------------------------------------------------- /2p/3linked/0bj/linked-loose+.js: -------------------------------------------------------------------------------- 1 | // 2 | // describe 3 | // 4 | 5 | let node1={ 6 | data:null, 7 | next:null 8 | } 9 | 10 | let node2={ 11 | data:null, 12 | next:null 13 | } 14 | 15 | let node3={ 16 | data:null, 17 | next:null 18 | } 19 | 20 | 21 | node3.data='c' 22 | node2.data='b' 23 | node1.data='a' 24 | 25 | node1.next=node2 26 | node2.next=node3 27 | 28 | node1.next.data//outputs QM 29 | node2.next.data//outputs QM 30 | node3.next.data//outputs QM 31 | -------------------------------------------------------------------------------- /2p/3linked/0bj/linked-loose.js: -------------------------------------------------------------------------------- 1 | // 2 | // describe 3 | // 4 | 5 | let list = { 6 | key: 'a', 7 | next: { 8 | key: 'b', 9 | next: { 10 | key: 'c', 11 | next: null 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /2p/3linked/1/2do/1.1linked-problems.js: -------------------------------------------------------------------------------- 1 | /** INSTRUCTIONS 2 | * 3 | * create one file by program 4 | * implement a method, function, non-function solution 5 | * solve each as requested 6 | * may use code from previous exercises 7 | * 8 | * PROBLEM 1 9 | * contains(v) 10 | * 11 | * look up for value v in the linked list 12 | * @arg {type} v - value; may be of a char, number, or object 13 | * @returns {bool} - true or false, if value v exists or not, 14 | * may use traverse 15 | * 16 | * @example 17 | * contains(3) 18 | * 19 | * PROBLEM 2 20 | * getTail() 21 | * 22 | * retrieve the node at the tail 23 | * @returns {Node} - Node at the tail or null if the list is empty 24 | * 25 | * @example 26 | * getTail() 27 | * 28 | * 29 | * @see {@link https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array} 30 | * @see {@link https://jsdoc.app} 31 | */ 32 | -------------------------------------------------------------------------------- /2p/3linked/1/2do/1.1linked-solution.js: -------------------------------------------------------------------------------- 1 | /** INSTRUCTIONS 2 | * 3 | * create one file by program 4 | * implement a method, function, non-function solution 5 | * solve each as requested 6 | * may use code from previous exercises 7 | * 8 | * PROBLEM 1 9 | * contains(v) 10 | * 11 | * look up for value v in the linked list 12 | * @arg {type} v - value; may be of a char, number, or object 13 | * @returns {bool} - true or false, if value v exists or not, 14 | * may use traverse 15 | * 16 | * @example 17 | * contains(3) 18 | * 19 | * PROBLEM 2 20 | * getTail() 21 | * 22 | * retrieve the node at the tail 23 | * @returns {Node} - Node at the tail or null if the list is empty 24 | * 25 | * @example 26 | * getTail() 27 | * 28 | * 29 | * @see {@link https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array} 30 | * @see {@link https://jsdoc.app} 31 | */ 32 | -------------------------------------------------------------------------------- /2p/3linked/1/Node4stu5es.js: -------------------------------------------------------------------------------- 1 | // 2 | // ES5 3 | // 4 | // with next QM 5 | // zeeAlso Node4stu6es 6 | 7 | 8 | function Node(data) {//constructor 9 | this.data = data 10 | this.next = null 11 | } 12 | -------------------------------------------------------------------------------- /2p/3linked/1/list4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // imports 3 | // Node (Node4stu5es.js) 4 | // 5 | 6 | 7 | //first 8 | let n1 = new Node(3) 9 | let n2 = new Node(-2) 10 | let n3 = new Node(1) 11 | 12 | console.log(n1.data) 13 | console.log('n1.next',n1.next) 14 | 15 | //then 16 | n1.next=n2 17 | n2.next=n3 18 | console.log('n2.next',n2.next) 19 | -------------------------------------------------------------------------------- /2p/3linked/1/traverse.js: -------------------------------------------------------------------------------- 1 | // 2 | //finally 3 | // 4 | 5 | const traverse=(n)=>{//es6 6 | let c=n//iterator 7 | while(c){//exists 8 | console.log(c.data) 9 | c=c.next 10 | } 11 | } 12 | 13 | traverse(n1) 14 | -------------------------------------------------------------------------------- /2p/3linked/5es/linked5es.js: -------------------------------------------------------------------------------- 1 | // 2 | // imports ES5 3 | // Node (Node4stu5es.js) 4 | // 5 | 6 | function Linked(n) {//node 7 | this.head = n//node 8 | this.tail = n//node 9 | this.size = 1 10 | 11 | this.getHead = getHead 12 | this.prepend = prepend 13 | this.append = append 14 | this.traverse = traverse 15 | //this.contains = contains 16 | } 17 | 18 | function getHead(){return this.head} 19 | 20 | function prepend(n){//new node 21 | n.next = this.head 22 | this.head=n 23 | this.size++ 24 | } 25 | 26 | function append(n){//new node 27 | n.next = null// 28 | this.tail.next=n 29 | this.tail=n 30 | this.size++ 31 | } 32 | 33 | function traverse(){ 34 | let c=this.head 35 | while(c){//exists 36 | //console.log(c.key) 37 | console.log(c.data) 38 | c=c.next 39 | } 40 | console.log('\n') 41 | } 42 | 43 | // 44 | // exercises 45 | // 46 | function contains(v){} 47 | function getTail(){} 48 | -------------------------------------------------------------------------------- /2p/3linked/5es/useLinked5es.js: -------------------------------------------------------------------------------- 1 | // 2 | // imports ES5 3 | // linked (linked5es.js) 4 | // 5 | 6 | //first 7 | //let n1=new Node('a',new Node('f')) 8 | let n1=new Node('a') 9 | let n2=new Node('b') 10 | 11 | let l = new Linked(n1)//new Node('a') 12 | l.traverse(l.getHead()) 13 | 14 | l.prepend(n2) 15 | l.traverse(l.getHead()) 16 | 17 | // 18 | l.append(new Node('c')) 19 | l.traverse(l.getHead()) 20 | 21 | // 22 | l.prepend(new Node('d')) 23 | l.traverse(l.getHead()) 24 | 25 | //then 26 | //console.log(l.contains('x'))//false 27 | //l.contains('a')//true 28 | -------------------------------------------------------------------------------- /2p/3linked/6es/Linked6es4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // singly 3 | // unsorted 4 | // 5 | // imports 6 | // Node 7 | 8 | class Linked { 9 | constructor(o){}//bject 10 | 11 | prepend(o){}//at begin 12 | append(o){}//at end 13 | insertAt(o,p){}//put, set, new 14 | 15 | setHead(o){} 16 | setTail(o){} 17 | setAt(o,p){} 18 | 19 | rm(o){}//remove 20 | rmHead(){} 21 | rmTail(){} 22 | rmAt(p){}//osition 23 | rmDuplicates(){} 24 | 25 | retrieve(k){}//get, search, contains 26 | traverse(){}//visit 27 | 28 | indexOf(){} 29 | contains(){} 30 | reverse(){} 31 | 32 | isFull(){} 33 | isEmpty(){} 34 | 35 | size(){} 36 | toString(){} 37 | print(){} 38 | makeEmpty(){}//clear, reset 39 | 40 | sublist(){} 41 | } 42 | -------------------------------------------------------------------------------- /2p/3linked/8imports/2do/useNode-problem.js: -------------------------------------------------------------------------------- 1 | // 1 insertAfter 2 | // insert newNode after node containing data 'b' 3 | // 4 | // -> c char 5 | // -> newNode Node 6 | // <- True if inserted 7 | // <- False if not found 8 | // 9 | // insertAfter(newNode,'b') 10 | // 11 | 12 | // 2 insertBefore 13 | // insert newNode before node containing data 'b' 14 | // 15 | // -> c char 16 | // -> newNode Node 17 | // <- True if inserted 18 | // <- False if not found 19 | // 20 | // insertBefore(newNode,'b') 21 | // 22 | -------------------------------------------------------------------------------- /2p/3linked/8imports/2do/useNode-solution.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * your solution here 4 | * 5 | */ 6 | -------------------------------------------------------------------------------- /2p/3linked/8imports/useNode.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | import Node from '../../../jrgp/linked/node.js' 5 | 6 | let n=new Node('b') 7 | 8 | console.log(n) -------------------------------------------------------------------------------- /2p/3linked/zeeAlso/circularList4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // circular-list 3 | // todo 4 | // 5 | 6 | class Circular {// constructor(){} 7 | previous(){} 8 | next(){} 9 | 10 | retrieve(){}//search 11 | insert(){} 12 | delete(){} 13 | } 14 | 15 | let l = new Circular() 16 | l.next() 17 | -------------------------------------------------------------------------------- /2p/3linked/zeeAlso/dcircular4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // doubly-circular-list 3 | // todo 4 | // 5 | 6 | class Dcircular {// constructor(){} 7 | previous(){} 8 | next(){} 9 | 10 | retrieve(){}//search 11 | insert(){} 12 | delete(){} 13 | } 14 | 15 | let l = new Dcircular() 16 | l.insert() 17 | -------------------------------------------------------------------------------- /2p/3linked/zeeAlso/doublyList4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // doubly-linked list 3 | // todo 4 | // 5 | 6 | class Doubly {// constructor(){} 7 | previous(){} 8 | next(){} 9 | 10 | retrieve(){}//search 11 | insert(){} 12 | delete(){} 13 | } 14 | 15 | let l = new Doubly() 16 | l.insert() 17 | -------------------------------------------------------------------------------- /2p/3linked/zeeAlso/queue5es4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // imports ES5 3 | // Node5es (data) 4 | // Linked 5 | // 6 | 7 | function Queue(n) { 8 | //props 9 | this.linked = new Linked() 10 | 11 | //methods 12 | this.enqueue = enqueue 13 | this.dequeue = dequeue 14 | this.front = front 15 | //this.back = back 16 | this.toString = toString 17 | this.empty = empty 18 | } 19 | 20 | //implement 21 | function enqueue(){} 22 | -------------------------------------------------------------------------------- /2p/3linked/zeeAlso/sortedList4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // A list that is sorted by a key-value 3 | // todo 4 | // 5 | 6 | class SortedList {// constructor(){} 7 | reset(){} 8 | size(){} 9 | retrieve(){}//search 10 | isFull(){} 11 | isEmpty(){} 12 | makeEmpty(){} 13 | getNext(){} 14 | insert(){} 15 | delete(){} 16 | } 17 | 18 | let l = new SortedList() 19 | l.isFull() 20 | -------------------------------------------------------------------------------- /2p/3linked/zeeAlso/stack5es4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // imports ES5 3 | // Node5es (data) 4 | // Linked 5 | // 6 | 7 | function Stack(n) { 8 | //props 9 | this.linked = new Linked() 10 | 11 | //methods 12 | this.push = push 13 | this.pop = pop 14 | this.peek = peek 15 | } 16 | 17 | //implement 18 | -------------------------------------------------------------------------------- /2p/3linked/zeeAlso/unsortedList4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | //items are placed in no particular order 3 | // todo 4 | // 5 | 6 | class UnsortedList {// constructor(){} 7 | makeEmpty(){} 8 | isFull(){} 9 | isEmpty(){} 10 | size(){} 11 | retrieve(){}//search 12 | insert(){} 13 | delete(){} 14 | getNext(){} 15 | reset(){} 16 | } 17 | 18 | let l = new UnsortedList() 19 | l.isFull() 20 | -------------------------------------------------------------------------------- /2p/6ds/1sorting/2do/2.1sorting-problems.js: -------------------------------------------------------------------------------- 1 | // 2 | // create one file by program 3 | // implement a method, function, non-function solution 4 | // solve each as requested 5 | // may use code from previous exercises 6 | // 7 | // SORTING 8 | 9 | 10 | //1. mergesort 11 | // sort(d) 12 | // -> d an array of random numbers 13 | // <- the random numbers sorted 14 | 15 | //2. quicksort 16 | // sort(d) 17 | // -> d an array of random numbers 18 | // <- the random numbers sorted 19 | 20 | //3. Array.sort() 21 | 22 | // forEach 23 | // + verify is sorted 24 | // + print 25 | // - time it took 26 | // - steps it tooks 27 | 28 | // create a 5-column table 29 | 30 | -------------------------------------------------------------------------------- /2p/6ds/1sorting/zeeAlso/runs.js: -------------------------------------------------------------------------------- 1 | // create random numbers 2 | // sort them 'n take steps 'n time it took 3 | // run 10 times 4 | 5 | let createNumbers=(n)=>{ 6 | let nums=[] 7 | for(let i=0; i{ 13 | console.time('run') 14 | n.sort() 15 | console.timeEnd('run') 16 | } 17 | 18 | 19 | run(createNumbers(1000000)) 20 | -------------------------------------------------------------------------------- /2p/6ds/5matrix/0/matrix4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | let aMatrix = [ 5 | [1,2], 6 | [4,5], 7 | [7,8] 8 | ] 9 | 10 | console.log(aMatrix[0]) // 11 | console.log(aMatrix[1][0])// 12 | console.log(aMatrix[1][4])// ?? 13 | console.log(aMatrix[4]) // ?? 14 | 15 | //then 16 | let A = new Array(3) 17 | A[0]= new Array(3) 18 | A[0][0]=-2 19 | //Math.random() 20 | -------------------------------------------------------------------------------- /2p/6ds/5matrix/2do/5.0problems2do.js: -------------------------------------------------------------------------------- 1 | // 2 | // pending 3 | // 4 | -------------------------------------------------------------------------------- /2p/6ds/5matrix/zeeAlso/matrixForOf4stu.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | let aMatrix = [ 5 | [1,2],//f0 6 | [4,5],//f1 7 | [7,8]//f2 8 | ] 9 | 10 | for (let f of aMatrix) { 11 | for (let c of f) { 12 | console.log(c) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /3p/1recursive/0/countDownIter.js: -------------------------------------------------------------------------------- 1 | // 2 | // iterative 3 | // vs 4 | // countDownRec.js 5 | // 6 | 7 | function countdown(number) { 8 | for(let i = number; i >= 1; i--) { 9 | console.log(i); 10 | } 11 | } 12 | 13 | countdown(5) 14 | -------------------------------------------------------------------------------- /3p/1recursive/0/countDownRec.js: -------------------------------------------------------------------------------- 1 | // 2 | // recursive 3 | // vs 4 | // countDownIter.js 5 | // 6 | 7 | function countDownToZero(n) { 8 | if (n < 1) {//base case 9 | return 10 | } else { 11 | console.log(n) 12 | countDownToZero(n - 1)//recursive call 13 | } 14 | } 15 | 16 | countDownToZero(5) 17 | -------------------------------------------------------------------------------- /3p/1recursive/2do/2.0problems.js: -------------------------------------------------------------------------------- 1 | // 2 | // SERIES 3 | // recursively 4 | // 5 | 6 | // 1. fibonacci 7 | // -> n 8 | // <- 1,1,2,...,n 9 | // 10 | // call 11 | // fibonacci(5) returns the 5 first numbers of the series 12 | 13 | // 2. power 14 | // -> b base 15 | // -> p power 16 | // <- b*b*...b (p times) 17 | // 18 | // call 19 | // power(2,3) returns 8 20 | 21 | // 3. factorial 22 | // -> n 23 | // <- 2*3*...*n 24 | // 25 | // call 26 | // factorial(3) returns 6 27 | -------------------------------------------------------------------------------- /3p/2trees/1linked/0/0tree-object.js: -------------------------------------------------------------------------------- 1 | /* 2 | binary tree 3 | */ 4 | 5 | let root={ 6 | d:'+', 7 | l:null,//eft 8 | r:null//ight 9 | } 10 | 11 | let n1={ 12 | d:1, 13 | l:null, 14 | r:null 15 | } 16 | 17 | let n2={ 18 | d:2, 19 | l:null, 20 | r:null 21 | } 22 | 23 | 24 | 25 | root.l=n1//left 26 | root.r=n2//right 27 | -------------------------------------------------------------------------------- /3p/2trees/1linked/0/traverse.js: -------------------------------------------------------------------------------- 1 | // 2 | // imports 3 | // Tree 4 | // 5 | 6 | function traverse(n){//node 7 | if (n!==null){//else //base case 8 | console.log(n.d)//traverse, analize, explore, search, TASK (console) 9 | 10 | //recursive calls 11 | traverse(n.l) 12 | traverse(n.r) 13 | }//else 14 | } 15 | 16 | 17 | 18 | traverse(root) 19 | console.log() 20 | -------------------------------------------------------------------------------- /3p/2trees/1linked/1/1tree.js: -------------------------------------------------------------------------------- 1 | // 2 | // ES5 tree 3 | // imports 4 | // preorder 5 | // 6 | 7 | function Node(o){ 8 | this.d=o//bject<->data 9 | this.l=null//eft 10 | this.r=null//ight 11 | } 12 | 13 | let p = new Node('+') 14 | let o1 = new Node(3) 15 | let o2 = new Node(-1) 16 | 17 | p.l = o1 18 | p.r = o2 19 | 20 | preorder(p) 21 | -------------------------------------------------------------------------------- /3p/2trees/1linked/1/2do/problem.js: -------------------------------------------------------------------------------- 1 | // 2 | // add two nodes 3 | // zee your notes 4 | // 5 | // then 6 | // call preorder 7 | // 8 | -------------------------------------------------------------------------------- /3p/2trees/1linked/1/preorder.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | function preorder(n){ 6 | if (n){//exists 7 | console.log(n.d) 8 | 9 | preorder(n.r) 10 | preorder(n.l) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /3p/2trees/1linked/2/2do/2.2tree-problems.js: -------------------------------------------------------------------------------- 1 | /** INSTRUCTIONS 2 | * 3 | * create one file by program 4 | * implement a method, function, non-function solution 5 | * solve each as requested 6 | * may use code from previous exercises 7 | * 8 | * 9 | * PROBLEM 1 10 | * inorder(n) 11 | * 12 | * traverses a tree in INORDER 13 | * @arg {tree} n - tree 14 | * 15 | * @example 16 | * inorder(root) 17 | * 18 | * PROBLEM 2 19 | * posorder(n) 20 | * 21 | * traverses a tree in POSORDER 22 | * @arg {tree} n - tree 23 | * 24 | * @example 25 | * posorder(root) 26 | * 27 | */ 28 | -------------------------------------------------------------------------------- /3p/2trees/1linked/2/together.js: -------------------------------------------------------------------------------- 1 | // 2 | // Tree 3 | // 4 | 5 | /* 6 | binary tree 7 | */ 8 | 9 | let root={ 10 | d:'+', 11 | l:null, 12 | r:null 13 | } 14 | 15 | let n1={ 16 | d:1, 17 | l:null, 18 | r:null 19 | } 20 | 21 | let n2={ 22 | d:2, 23 | l:null, 24 | r:null 25 | } 26 | 27 | 28 | root.l=n1 29 | root.r=n2 30 | 31 | // 32 | // imports 33 | // Tree 34 | // 35 | 36 | function traverse(n){ 37 | if (n!==null){//else //base case 38 | console.log(n.d)//traverse, analize, explore, TASK (console) 39 | traverse(n.l) 40 | traverse(n.r) 41 | }//else 42 | } 43 | 44 | 45 | 46 | traverse(root) 47 | -------------------------------------------------------------------------------- /3p/2trees/2do/problem2do1.js: -------------------------------------------------------------------------------- 1 | // 2 | // your binary tree solution here 3 | // 4 | -------------------------------------------------------------------------------- /3p/2trees/2do/problem2do2.js: -------------------------------------------------------------------------------- 1 | // 2 | // your solution here 3 | // 4 | // pick one: 5 | // binary search tree 6 | // ternary tree 7 | // avl 8 | // heap 9 | // 10 | -------------------------------------------------------------------------------- /3p/2trees/array2do/2do.js: -------------------------------------------------------------------------------- 1 | // 2 | // pending 3 | // -------------------------------------------------------------------------------- /3p/3graphs/1array-/0/graph.js: -------------------------------------------------------------------------------- 1 | // 2 | // simplest graph qm 3 | // 4 | 5 | friends = { 6 | "Alice" : ["Bob", "Diana", "Fred"], 7 | "Bob" : ["Alice", "Cynthia", "Diana"], 8 | "Cynthia" : ["Bob"], 9 | "Diana" : ["Alice", "Bob", "Fred"], 10 | "Elise" : ["Fred"], 11 | "Fred" : ["Alice", "Diana", "Elise"] 12 | } 13 | 14 | friends['Fred'] 15 | -------------------------------------------------------------------------------- /3p/3graphs/1array-/1/graph-array.js: -------------------------------------------------------------------------------- 1 | // 2 | // graph as anArray 3 | // 4 | -------------------------------------------------------------------------------- /3p/3graphs/1array-/1/graph-ds.js: -------------------------------------------------------------------------------- 1 | // 2 | // graph as another data structure 3 | // 4 | -------------------------------------------------------------------------------- /3p/3graphs/1array-/1/graph-linked.js: -------------------------------------------------------------------------------- 1 | // 2 | // graph as aLinked 3 | // 4 | -------------------------------------------------------------------------------- /3p/3graphs/1array-/1/graph-map.js: -------------------------------------------------------------------------------- 1 | // 2 | // graph as aMap 3 | // 4 | -------------------------------------------------------------------------------- /3p/3graphs/1array-/1/graph-obj.js: -------------------------------------------------------------------------------- 1 | // 2 | // graph as anObject 3 | // 4 | -------------------------------------------------------------------------------- /3p/3graphs/1array-/1/graph-set.js: -------------------------------------------------------------------------------- 1 | // 2 | // graph as aSet 3 | // 4 | -------------------------------------------------------------------------------- /3p/3graphs/1array-/2do/3.1weighted2do.js: -------------------------------------------------------------------------------- 1 | // 2 | // dcomplab exercise 3 | // complete graph as matrix 4 | // -------------------------------------------------------------------------------- /3p/3graphs/1array-/4useGraph/useGraph-m-sample.js: -------------------------------------------------------------------------------- 1 | import GraphSample from '../../../../jrgp/graph/Graph-m-sample.js' 2 | import Graph from '../../../../jrgp/graph/Graph-m.js' 3 | 4 | // 5 | // ok - asMatrix 6 | // 7 | 8 | (function () { 9 | console.log('... ::: useGraphSample-m begins ::: ...\n') 10 | 11 | let s = new GraphSample() 12 | let l = new Graph(s.getLoopy()) 13 | let u = new Graph(s.getUndirected()) 14 | let d = new Graph(s.getDirected()) 15 | let p = new Graph(s.getPlanar()) 16 | let m = new Graph(s.getCompleteDummy()) 17 | let c = new Graph(s.getComplete(7)) 18 | // let x = new Graph() 19 | // let x = new Graph([]) 20 | // let x = new Graph([[]]) 21 | 22 | l.print('A loopy graph') 23 | u.print('A simple undirected graph') 24 | d.print('A simple directed graph') 25 | // p.print('A planar graph') 26 | // m.print('A complete dummy graph') 27 | c.print('A complete graph')// x.print('x') 28 | 29 | console.log('\n... ::: useGraphSample-m ends ::: ...') 30 | })() 31 | -------------------------------------------------------------------------------- /3p/3graphs/1array-/5/2do/5.1incidence1.js: -------------------------------------------------------------------------------- 1 | // 2 | // dcomplab exercises 3 | // incidence matrix1 4 | // -------------------------------------------------------------------------------- /3p/3graphs/1array-/5/2do/5.1incidence2.js: -------------------------------------------------------------------------------- 1 | // 2 | // dcomplab exercises 3 | // incidence matrix2 (könisberg) 4 | // 5 | -------------------------------------------------------------------------------- /3p/3graphs/1array-/5/2do/5.1incidence3.js: -------------------------------------------------------------------------------- 1 | // 2 | // dcomplab exercises 3 | // incidence matrix3 4 | // -------------------------------------------------------------------------------- /3p/3graphs/1array-/zeeAlso/corEtal09pp611di.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | let directed = [ 6 | [0, 1, 0, 1, 0, 0], 7 | [0, 0, 0, 0, 1, 0], 8 | [0, 0, 0, 0, 1, 1], 9 | [0, 1, 0, 0, 0, 0], 10 | [0, 0, 0, 1, 0, 0], 11 | [0, 0, 0, 0, 0, 1], 12 | ] 13 | -------------------------------------------------------------------------------- /3p/3graphs/1array-/zeeAlso/corEtal09pp611un.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | let undirected = [ 6 | [0, 1, 0, 0, 1], 7 | [1, 0, 1, 1, 1], 8 | [0, 1, 0, 1, 0], 9 | [0, 1, 1, 0, 1], 10 | [1, 1, 0, 1, 0], 11 | ] 12 | -------------------------------------------------------------------------------- /3p/3graphs/1array-/zeeAlso/tree-vs-graph.js: -------------------------------------------------------------------------------- 1 | // 2 | // what is it : aTree or aGraph 3 | // 4 | 5 | let qm = [ 6 | [0, 1, 0, 0],//1 7 | [1, 0, 1, 1],//2 8 | [0, 1, 0, 1],//3 9 | [0, 1, 1, 0],//4 10 | ] 11 | -------------------------------------------------------------------------------- /3p/3graphs/2do/problem2do1.js: -------------------------------------------------------------------------------- 1 | // 2 | // your undirected graph solution here 3 | // 4 | -------------------------------------------------------------------------------- /3p/3graphs/2do/problem2do2.js: -------------------------------------------------------------------------------- 1 | // 2 | // your solution here 3 | // 4 | // pick one: 5 | // digraph 6 | // dfs on an undirected graph 7 | // bfs on an undirected graph 8 | // 9 | -------------------------------------------------------------------------------- /3p/3graphs/linked2do/2do.js: -------------------------------------------------------------------------------- 1 | // 2 | // design node (object) for a 3 | // weighted graph incidence list 4 | // -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ds-xy-js ('23) 2 | 3 | An first course on data structures and algorithms in three parts, for fresh students, in javascript with an ecmascript 6+ touch. 4 | -------------------------------------------------------------------------------- /docs/0.md: -------------------------------------------------------------------------------- 1 | # Zero 2 | 3 | ## code directory organization still in progress 4 | 5 | ```javascript 6 | 7 | if (isAwesome){ 8 | return true 9 | } 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/1.1series.md: -------------------------------------------------------------------------------- 1 | # Series 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/1.2complexity.md: -------------------------------------------------------------------------------- 1 | # Complexity 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/1.3vector.md: -------------------------------------------------------------------------------- 1 | # Vector 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/1.4sorting.md: -------------------------------------------------------------------------------- 1 | # Sorting 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/1.5searching.md: -------------------------------------------------------------------------------- 1 | # Searching 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/1.6ds.md: -------------------------------------------------------------------------------- 1 | # DS1 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/2.1sorting.md: -------------------------------------------------------------------------------- 1 | # Sorting 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/2.2lrecursive.md: -------------------------------------------------------------------------------- 1 | # Recursive 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/2.3stack.md: -------------------------------------------------------------------------------- 1 | # Stack 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/2.4queue.md: -------------------------------------------------------------------------------- 1 | # Queue 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/2.5matrix.md: -------------------------------------------------------------------------------- 1 | # Matrix 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/2.6ds.md: -------------------------------------------------------------------------------- 1 | # DS2 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/3.1linkedlist.md: -------------------------------------------------------------------------------- 1 | # Linkedlist 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/3.2tree.md: -------------------------------------------------------------------------------- 1 | # Tree 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/3.3graph.md: -------------------------------------------------------------------------------- 1 | # Graph 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /docs/3.4ds.md: -------------------------------------------------------------------------------- 1 | # DS3 2 | 3 | ```javascript 4 | 5 | if (isAwesome){ 6 | return true 7 | } 8 | ``` 9 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | console.log('Hello ES6+ DS world') 5 | -------------------------------------------------------------------------------- /jrgp/graph/Graph-m-sample.js: -------------------------------------------------------------------------------- 1 | import M from '../matrix/Matrix.js' 2 | // 3 | // ok - asMatrix 4 | // 5 | export default 6 | // 7 | // 8 | // 9 | class GraphSample { 10 | 11 | getDisconected(){} 12 | getCycle(){} 13 | getWheel(){} 14 | getRegular(){} 15 | getInduced(){} 16 | getIsomorphic(){} 17 | getEulerian(){} 18 | getHamiltonian(){} 19 | getWeighted(){} 20 | getMultipleGraph(){} 21 | 22 | getComplete(n){ 23 | let g = new M(n) 24 | g.ones() 25 | for (let i = 0; i < n; i++) 26 | g.setValue(i,i,0) 27 | return g.getMatrix() 28 | } 29 | 30 | getCompleteDummy(){ 31 | return [ 32 | [0, 1, 1, 1, 1], 33 | [1, 0, 1, 1, 1], 34 | [1, 1, 0, 1, 1], 35 | [1, 1, 1, 0, 1], 36 | [1, 1, 1, 1, 0], 37 | ] 38 | } 39 | 40 | getPlanar(){ 41 | return [ 42 | [0, 1, 1, 1, 0, 0, 0, 0], 43 | [1, 0, 1, 0, 0, 1, 0, 1], 44 | [1, 1, 0, 1, 1, 0, 0, 1], 45 | [1, 0, 1, 0, 1, 0, 0, 0], 46 | [0, 0, 1, 1, 0, 0, 1, 1], 47 | [0, 1, 0, 0, 0, 0, 1, 1], 48 | [0, 0, 0, 0, 1, 1, 0, 1], 49 | [0, 1, 1, 0, 1, 1, 1, 0] 50 | ]//n 51 | } 52 | 53 | aNew(){//console.log('A null graph...') let n =[] 54 | return [[]] 55 | } 56 | 57 | getUndirected(){ 58 | return [ 59 | [0,1,0,0], 60 | [1,0,1,1], 61 | [0,1,0,1], 62 | [0,1,1,0] 63 | ] 64 | } 65 | 66 | getDirected(){ 67 | return [ 68 | [0,1,0,0], 69 | [0,0,1,0], 70 | [0,0,0,1], 71 | [0,1,0,0] 72 | ] 73 | } 74 | 75 | getLoopy(){ 76 | return [ 77 | [1,1],//x7 78 | [1,0],//x6 79 | ] 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /jrgp/graph/Graph-m-util.js: -------------------------------------------------------------------------------- 1 | import M from '../matrix/Matrix' 2 | // 3 | //use @ in wepackconfig 4 | // 5 | export default 6 | // 7 | // qm 8 | // 9 | class Graph { 10 | isDirected(g) { 11 | for (let r = 0; r < g.length; r++) 12 | for (let c = r; c < g.length; c++) 13 | if (g[r][c] != g[c][r]) 14 | return true 15 | return false 16 | } 17 | 18 | isDirectedAlt(g) { 19 | return !g.isSymmetric() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /jrgp/graph/Graph-m.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ok 4 | // 5 | class Graph { 6 | 7 | constructor(o){//verify it is a matrix 8 | if ((o instanceof Array) && (o[0] instanceof Array)) 9 | this.m=o 10 | else 11 | throw new Error(` 12 | @jrgp.Graph() 13 | graph not initialized 14 | got: ${typeof(o)} 15 | must be: an array of arrays 16 | `) 17 | } 18 | 19 | addVertex(v){ 20 | this.m[v]=0 21 | } 22 | 23 | addEdge(e,f){//console.log('::'+typeof(this.m[e])) 24 | if (typeof(this.m[e])==='number'){ 25 | this.m[e]=[] 26 | }this.m[e][f]=1 27 | } 28 | 29 | // 30 | // compulsory 31 | // 32 | fill(){ 33 | for (let i = 0; i < this.m.length; i++) { 34 | for (let j = 0; j < this.m.length; j++) { 35 | if (this.m[i][j]===undefined) 36 | this.m[i][j]=0 37 | } 38 | } 39 | } 40 | 41 | toString(){ 42 | let s='' 43 | if (this.m.length>1 && this.m[0].length>0){ 44 | for (let i = 0; i < this.m.length; i++) { 45 | for (let j = 0; j < this.m[i].length; j++) { 46 | s+=this.m[i][j]+' ' 47 | }s+='\n' 48 | }return s 49 | } 50 | else 51 | throw new Error(` 52 | @jrgp.Graph.toString() 53 | cannot print 54 | not a graph 55 | `) 56 | } 57 | 58 | print(u='undescribed graph...'){ 59 | console.log(u) 60 | console.log(this.toString()) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /jrgp/graph/graph2do1.js: -------------------------------------------------------------------------------- 1 | // 2 | // graph types 1 3 | // 4 | 5 | class Graph { 6 | //all-boolean 7 | hasLoops(g)//pseudo- 8 | hasParallel(g)//o 9 | //noLoops 10 | //noParallels 11 | isSimple(g){} 12 | 13 | isDigraph(g){}//O 14 | isWeighted(g){}//o5 15 | isSubgraph(g,b){} 16 | isComplete(g){}//o 17 | isRegular(g){} 18 | isIsomorphic(g,b){} 19 | isPlanar(g){} 20 | isBipartite(g){} 21 | 22 | isAcyclic(g){}//4trees 23 | } 24 | -------------------------------------------------------------------------------- /jrgp/graph/graph2do2.js: -------------------------------------------------------------------------------- 1 | // 2 | // traversal ops 2 3 | // 4 | 5 | class Graph { 6 | dfs(g,v){} 7 | bfs(g,v){} 8 | shortest(g){}//path 9 | diameter(g){} 10 | radio(g){} 11 | 12 | //walks, paths 13 | //circuits, cycles 14 | //distance 15 | 16 | isCircuit(g){} 17 | isEulerian(g){} 18 | isHamiltonian(g){} 19 | } 20 | -------------------------------------------------------------------------------- /jrgp/graph/graph2do3.js: -------------------------------------------------------------------------------- 1 | // 2 | // advanced ops 3 3 | // 4 | 5 | class Graph { 6 | isAdjacent(v,u){}// 7 | isIncident(e,f){}// 8 | isPrecedesor(e,f){} 9 | isReachable(v,u){}// 10 | 11 | isConnected(g){}//O= 12 | isDisconnected(g){}//O 13 | 14 | neighbourhood(v){} 15 | neighbourhood(e){} 16 | } 17 | -------------------------------------------------------------------------------- /jrgp/graph/graph2do4.js: -------------------------------------------------------------------------------- 1 | // 2 | // SNA ops 4 3 | // 4 | 5 | class Graph { 6 | //float 7 | density(g){} 8 | betweeness(g){} 9 | closeness(g){} 10 | connectivity(g){} 11 | cohesion(g){} 12 | eccentricity(g){} 13 | 14 | //degree ops 15 | inDegree(v){}// 16 | outDegree(v){}// 17 | degree(v){}//neighbours 18 | } 19 | -------------------------------------------------------------------------------- /jrgp/graph/graph2do5.js: -------------------------------------------------------------------------------- 1 | // 2 | // ops 5 3 | // 4 | 5 | class Graph { 6 | //set-like 7 | //union 8 | //intersection 9 | //else 10 | } 11 | -------------------------------------------------------------------------------- /jrgp/graph/graph2do6.js: -------------------------------------------------------------------------------- 1 | // 2 | // ops 6 3 | // 4 | 5 | class Graph { 6 | in2list(m){}// 7 | in2matrix(l){}// 8 | in2incidences(a){} 9 | in2adjacencies(i){} 10 | 11 | getLoopy(){} 12 | getUndirected(){} 13 | getDirected(){} 14 | getTriangle(){} 15 | 16 | toString() 17 | print() 18 | } 19 | -------------------------------------------------------------------------------- /jrgp/graph/graph5es.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES5 4 | // 5 | function Graph() { 6 | this.addNode=addNode 7 | this.addEdge=addEdge 8 | 9 | this.removeNode=removeNode 10 | this.removeEdge=removeEdge 11 | 12 | this.findNode=findNode 13 | } 14 | 15 | function addNode(n){} 16 | function addEdge(n1,n2){} 17 | function removeNode(n){} 18 | function removeEdge(n1,n2){} 19 | function findNode(n){} 20 | -------------------------------------------------------------------------------- /jrgp/graph/graph6es.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Graph { 6 | constructor(g){}//from file, str, mtx 7 | 8 | addVertex(v){}//node 9 | addVertex(v,u,e){} 10 | removeVertex(v){}// 11 | getVertices(){} 12 | 13 | addEdge(e,f){}// 14 | addEdge(e){} 15 | removeEdge(e){}// 16 | removeEdge(i,j){} 17 | 18 | findNode(v){} 19 | 20 | getEdges(){} 21 | getWeight(e){} 22 | getWeight(v,u){} 23 | 24 | order(){}// 25 | size(){}// 26 | 27 | //bool 28 | hasVertex() 29 | hasEdge() 30 | 31 | makeEmpty(){} 32 | isFull(){} 33 | isEmpty(){} 34 | } 35 | -------------------------------------------------------------------------------- /jrgp/linked/node.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Node { 6 | constructor(d, n = null){ 7 | this._data=d 8 | this._next=n 9 | } 10 | 11 | get data(){ 12 | return this._data 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /jrgp/linked/node5es.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES5 4 | // 5 | function Node(d,n=null) { 6 | this.data = d//data 7 | this.next=n//link 8 | } 9 | -------------------------------------------------------------------------------- /jrgp/linked/node6es.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Node { 6 | constructor(d, n = null){ 7 | this._data=d 8 | this._next=n 9 | } 10 | 11 | get data(){ 12 | return this._data 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /jrgp/math.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | export const mysum = 'this is sum' 5 | -------------------------------------------------------------------------------- /jrgp/matrix/Matrix.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // todo 4 | // then as ES6 5 | // 6 | class Matrix { 7 | constructor(r,c){ 8 | if (typeof(c)==='undefined') 9 | c=r//4identity 10 | 11 | this._M = new Array(r) 12 | if (r!=null && c!=null){ 13 | this.r=r,this.c=c 14 | for (let i = 0; i < this.r; i++) 15 | this._M[i]=new Array(c) 16 | } 17 | else throw new Error(` 18 | @jrgp.matrix 19 | matrix undefined 20 | `) 21 | } 22 | 23 | fill(r){ 24 | this.ones(r) 25 | } 26 | 27 | // -> 28 | // <- 29 | // this._M modified 30 | ones(v=1){ 31 | for (let i = 0; i < this.r; i++) { 32 | for (let j = 0; j < this.c; j++) { 33 | this._M[i][j]=v 34 | } 35 | } 36 | } 37 | 38 | zeroes(){ 39 | for (let i = 0; i < this.r; i++) { 40 | this._M[i]=new Array(this.r).fill(0) 41 | } 42 | } 43 | 44 | random(){ 45 | for (let i = 0; i < this.r; i++) { 46 | for (let j = 0; j < this.c; j++) { 47 | this._M[i][j]=Math.random() 48 | } 49 | } 50 | } 51 | 52 | identity() { 53 | this.zeroes() 54 | for (let i = 0; i < this.r; i++) 55 | this._M[i][i]=1 56 | } 57 | 58 | // -> row, column, value 59 | // <- 60 | // this._M modified 61 | setValue(r,c,v){ 62 | this._M[r][c]=v 63 | } 64 | 65 | // -> row, column 66 | // <- value at (r,c) 67 | getValue(r,c){ 68 | return this._M[r][c] 69 | } 70 | 71 | // -> row 72 | // <- array at r 73 | getRow(r) {//validate qm 74 | return this._M[r] 75 | } 76 | 77 | // -> columns 78 | // <- array at c 79 | getCol(c) {//validate 80 | let v = new Array() 81 | for (let j = 0; j < this._M.length; j++) { 82 | v.push(this._M[j][c]) 83 | } 84 | return v 85 | } 86 | 87 | // -> 88 | // <- this._M 89 | getMatrix(){ 90 | return this._M 91 | } 92 | 93 | 94 | // -> array of arrays 95 | // <- 96 | // this._M modified 97 | setMatrix(m){//validate 98 | for (let i = 0; i < this.r; i++) { 99 | for (let j = 0; j < this.c; j++) { 100 | this._M[i][j]=m[i][j] 101 | } 102 | } 103 | } 104 | 105 | // -> m: array of arrays 106 | // <- a: array of arrays = this._M + m 107 | sum(m){//validate 108 | if (this.r=== m.length && this.c ===m[0].length){ 109 | let a = new Array(m.length) 110 | for (let i = 0; i < this.r; i++) { 111 | a[i]=new Array(m[i].length) 112 | for (let j = 0; j < this.c; j++) { 113 | a[i][j]=this._M[i][j]+m[i][j] 114 | } 115 | }return a 116 | } 117 | else throw new Error(` 118 | jrgp...Matrices 119 | have different dimensions 120 | `) 121 | } 122 | 123 | // -> 124 | // <- a new Matrix object 125 | clone(){ 126 | let c=new Matrix(this.r,this.c) 127 | c.setMatrix(this._M) 128 | return c 129 | } 130 | 131 | // -> 132 | // <- true if this.M is squared 133 | // <- false if not 134 | isSquared(){ 135 | if (this.r===this.c) 136 | return true 137 | else 138 | return false 139 | } 140 | 141 | // -> 142 | // <- true if this.M is symmetric 143 | // <- false if not 144 | isSymmetric() { 145 | if (!this.isSquared()) 146 | return false 147 | for (let r = 0; r < this.r; r++) 148 | for (let c = r; c < this.r; c++) 149 | if (this._M[r][c] != this._M[c][r]) 150 | return false 151 | return true 152 | } 153 | 154 | isSymmetricAlt(){ 155 | //if (!this.isSquared()){return false} 156 | for(var j=0;j 164 | // <- this._M as astring 165 | toString(){ 166 | let m='' 167 | for (let i = 0; i < this.r; i++) { 168 | for (let j = 0; j < this.c; j++) { 169 | if (typeof(this._M[i][j])!=='undefined') 170 | m+=this._M[i][j]+'\t' 171 | else throw new Error(` 172 | @jrgp.matrix.toString 173 | matrix not initialized 174 | `) 175 | }m+='\n' 176 | }return m 177 | } 178 | 179 | print(m='-> nomsg, add title'){ 180 | console.log(m) 181 | console.log(this.toString()) 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /jrgp/matrix/Matrix2do.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // todo 4 | // 5 | class Matrix { 6 | constructor(){}// 7 | ones(){}// 8 | zeroes(){}// 9 | random(){}// 10 | 11 | identity(r){}// 12 | range(){} 13 | fill(k){}// 14 | print(){}// 15 | setMatrix(m) {}// 16 | setValue(r,c,v) {}// 17 | 18 | //<- string 19 | toString(){}// 20 | 21 | //scalar 22 | getValue(r,c) {}// 23 | 24 | //<- Array 25 | getRow(r){}// 26 | getCol(c){}// 27 | 28 | //<- boolean 29 | isSquared(){}// 30 | isSymmetric(){}// 31 | isIdentity(){} 32 | isTriangular(){} 33 | isLowerTriangular(){} 34 | isUpperTriangular(){} 35 | 36 | isRowEchelon(){}//more matrix ops 37 | isCirculant(){}//more matrix ops 38 | 39 | //<- Array of Array 40 | getMatrix() {}// 41 | clone() {}// 42 | transpose(){} 43 | trace(){} 44 | 45 | sum(){}//et al 46 | } 47 | -------------------------------------------------------------------------------- /jrgp/o/2do/coin500.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | -------------------------------------------------------------------------------- /jrgp/o/2do/dice1.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | -------------------------------------------------------------------------------- /jrgp/o/2do/dice500.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | -------------------------------------------------------------------------------- /jrgp/o/coin1.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | 5 | function coin() { 6 | n=Math.random() 7 | 8 | if (n<0.5){ 9 | return 'cara' 10 | } 11 | else{ 12 | return 'sol' 13 | } 14 | } 15 | 16 | console.log(coin()) 17 | console.log(coin()) 18 | console.log(coin()) 19 | console.log(coin()) 20 | console.log(coin()) 21 | -------------------------------------------------------------------------------- /jrgp/queue/2do.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Twodo {} 6 | -------------------------------------------------------------------------------- /jrgp/random/2do.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Twodo {} 6 | -------------------------------------------------------------------------------- /jrgp/series/2do.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Twodo {} 6 | -------------------------------------------------------------------------------- /jrgp/sort/2do.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Twodo {} 6 | -------------------------------------------------------------------------------- /jrgp/stack/2do.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Twodo {} 6 | -------------------------------------------------------------------------------- /jrgp/tree/tree5es.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES5 4 | // zeeAlso tree6es.js 5 | // 6 | function Tree() { 7 | this.addNode=addNode 8 | this.removeNode=removeNode 9 | this.findNode=findNode 10 | } 11 | 12 | function addNode(n){} 13 | function removeNode(n){} 14 | function findNode(n){} 15 | -------------------------------------------------------------------------------- /jrgp/tree/tree6es.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // zeeAlso tree5es.js 5 | // 6 | class Tree { 7 | constructor(n){} 8 | 9 | addNode(n){} 10 | removeNode(n){} 11 | findNode(n){} 12 | 13 | preorder(){} 14 | inorder(){} 15 | posorder(){} 16 | 17 | max(){} 18 | min(){} 19 | 20 | } 21 | -------------------------------------------------------------------------------- /jrgp/useMath.js: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // 4 | import {mysum} from './math.js' 5 | 6 | console.log(mysum) 7 | -------------------------------------------------------------------------------- /jrgp/util/2do.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Twodo {} 6 | -------------------------------------------------------------------------------- /jrgp/vector/2do.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Twodo {} 6 | -------------------------------------------------------------------------------- /jrgp/z_dp/2do.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Twodo {} 6 | -------------------------------------------------------------------------------- /jrgp/z_hash/2do.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Twodo {} 6 | -------------------------------------------------------------------------------- /jrgp/z_string/2do.js: -------------------------------------------------------------------------------- 1 | export default 2 | // 3 | // ES6 4 | // 5 | class Twodo {} 6 | -------------------------------------------------------------------------------- /newBranch.txt: -------------------------------------------------------------------------------- 1 | Created in newBranch 2 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "nodejs", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "@types/node": "^18.0.6", 13 | "node-fetch": "^3.2.6" 14 | } 15 | }, 16 | "node_modules/@types/node": { 17 | "version": "18.0.6", 18 | "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.6.tgz", 19 | "integrity": "sha512-/xUq6H2aQm261exT6iZTMifUySEt4GR5KX8eYyY+C4MSNPqSh9oNIP7tz2GLKTlFaiBbgZNxffoR3CVRG+cljw==" 20 | }, 21 | "node_modules/data-uri-to-buffer": { 22 | "version": "4.0.0", 23 | "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", 24 | "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==", 25 | "engines": { 26 | "node": ">= 12" 27 | } 28 | }, 29 | "node_modules/fetch-blob": { 30 | "version": "3.1.5", 31 | "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.1.5.tgz", 32 | "integrity": "sha512-N64ZpKqoLejlrwkIAnb9iLSA3Vx/kjgzpcDhygcqJ2KKjky8nCgUQ+dzXtbrLaWZGZNmNfQTsiQ0weZ1svglHg==", 33 | "funding": [ 34 | { 35 | "type": "github", 36 | "url": "https://github.com/sponsors/jimmywarting" 37 | }, 38 | { 39 | "type": "paypal", 40 | "url": "https://paypal.me/jimmywarting" 41 | } 42 | ], 43 | "dependencies": { 44 | "node-domexception": "^1.0.0", 45 | "web-streams-polyfill": "^3.0.3" 46 | }, 47 | "engines": { 48 | "node": "^12.20 || >= 14.13" 49 | } 50 | }, 51 | "node_modules/formdata-polyfill": { 52 | "version": "4.0.10", 53 | "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", 54 | "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", 55 | "dependencies": { 56 | "fetch-blob": "^3.1.2" 57 | }, 58 | "engines": { 59 | "node": ">=12.20.0" 60 | } 61 | }, 62 | "node_modules/node-domexception": { 63 | "version": "1.0.0", 64 | "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", 65 | "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", 66 | "funding": [ 67 | { 68 | "type": "github", 69 | "url": "https://github.com/sponsors/jimmywarting" 70 | }, 71 | { 72 | "type": "github", 73 | "url": "https://paypal.me/jimmywarting" 74 | } 75 | ], 76 | "engines": { 77 | "node": ">=10.5.0" 78 | } 79 | }, 80 | "node_modules/node-fetch": { 81 | "version": "3.2.6", 82 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.6.tgz", 83 | "integrity": "sha512-LAy/HZnLADOVkVPubaxHDft29booGglPFDr2Hw0J1AercRh01UiVFm++KMDnJeH9sHgNB4hsXPii7Sgym/sTbw==", 84 | "dependencies": { 85 | "data-uri-to-buffer": "^4.0.0", 86 | "fetch-blob": "^3.1.4", 87 | "formdata-polyfill": "^4.0.10" 88 | }, 89 | "engines": { 90 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 91 | }, 92 | "funding": { 93 | "type": "opencollective", 94 | "url": "https://opencollective.com/node-fetch" 95 | } 96 | }, 97 | "node_modules/web-streams-polyfill": { 98 | "version": "3.2.1", 99 | "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", 100 | "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", 101 | "engines": { 102 | "node": ">= 8" 103 | } 104 | } 105 | }, 106 | "dependencies": { 107 | "@types/node": { 108 | "version": "18.0.6", 109 | "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.6.tgz", 110 | "integrity": "sha512-/xUq6H2aQm261exT6iZTMifUySEt4GR5KX8eYyY+C4MSNPqSh9oNIP7tz2GLKTlFaiBbgZNxffoR3CVRG+cljw==" 111 | }, 112 | "data-uri-to-buffer": { 113 | "version": "4.0.0", 114 | "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", 115 | "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==" 116 | }, 117 | "fetch-blob": { 118 | "version": "3.1.5", 119 | "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.1.5.tgz", 120 | "integrity": "sha512-N64ZpKqoLejlrwkIAnb9iLSA3Vx/kjgzpcDhygcqJ2KKjky8nCgUQ+dzXtbrLaWZGZNmNfQTsiQ0weZ1svglHg==", 121 | "requires": { 122 | "node-domexception": "^1.0.0", 123 | "web-streams-polyfill": "^3.0.3" 124 | } 125 | }, 126 | "formdata-polyfill": { 127 | "version": "4.0.10", 128 | "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", 129 | "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", 130 | "requires": { 131 | "fetch-blob": "^3.1.2" 132 | } 133 | }, 134 | "node-domexception": { 135 | "version": "1.0.0", 136 | "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", 137 | "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" 138 | }, 139 | "node-fetch": { 140 | "version": "3.2.6", 141 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.6.tgz", 142 | "integrity": "sha512-LAy/HZnLADOVkVPubaxHDft29booGglPFDr2Hw0J1AercRh01UiVFm++KMDnJeH9sHgNB4hsXPii7Sgym/sTbw==", 143 | "requires": { 144 | "data-uri-to-buffer": "^4.0.0", 145 | "fetch-blob": "^3.1.4", 146 | "formdata-polyfill": "^4.0.10" 147 | } 148 | }, 149 | "web-streams-polyfill": { 150 | "version": "3.2.1", 151 | "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", 152 | "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==" 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodejs", 3 | "version": "1.0.0", 4 | "type": "module", 5 | "description": "", 6 | "main": "index.js", 7 | "scripts": { 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "@types/node": "^18.0.6", 15 | "node-fetch": "^3.2.6" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /replit.nix: -------------------------------------------------------------------------------- 1 | { pkgs }: { 2 | deps = [ 3 | pkgs.nodejs-16_x 4 | pkgs.nodePackages.typescript-language-server 5 | pkgs.yarn 6 | pkgs.replitPackages.jest 7 | ]; 8 | } --------------------------------------------------------------------------------