#Learning Tests and Node Jest
We immediately began with test cases; given a porblem domain, finding a solution and creating tests using node js. eg: const greet = require('../lib/greet.js');
describe('Greet Module', function () { describe('#Input', function () { it('should take in a string', function () { expect(greet(123)).toEqual(null); }); it('should take in the argument world', function () { expect(greet('World')).toEqual('Hello World'); }); }); });
#Learning Error First Callbacks in line 4 we require in our js file we are testing for in line 6&7 we pass in a string describing our test and create a function, expecting a given method and value then running jest to see if our code runs as intended.
We also started impleementing error first methods, making our code blocks start with checking for an error before completely executuing the code, or stopping the execution with a console.error like so... fs.readFile(paths[2], (err, data) => { if (err) console.error(err); results.push(data.toString); //buffers and comes back as binary unless we push to string callback(null, results); });
#Single Linked Lists Most importnatlnyl we learned how to create and implement linked lists data structures and slingle linked list constructors like so... const Nd = require('./nd') // import Nd from './nd'
class SLL { create a single linked list class constructor() { this.head = null this is simpply a header that holds all the nested linked list nodes }
insertHead(val) { every new node contains a new value that looks like { value: 7, next: {... let nd = new Nd(val)
nd.next = this.head
this.head = nd
return this
}
insertEnd(val) { let nd = new Nd(val)
if (!this.head) {
this.head = nd
return this
}
for (var itr = this.head; itr.next; itr = itr.next); here we create a for loop to iterate throught the nodes until the
itr.next = nd final node =null and the collective linked lists are retruned
return this
}
remove() { if (head === null) return; if (head.data == data) { head = head.next; return; } } }
module.exports = SLL in this final line we create a module from this file so the data and constructor can be used and utilized throughout the entire application be requiring this file be navigating throught the file path and calling in the file like so ... const SLL = require('../file-path/file-name.js')