This is a series of testing exercises using the super lightweight Javascript unit testing library: "Tinytest.js" and a modification of TinyTest called "SimpleTest.js" developed in the "Watch and Code" series and altered by myself.
The idea is to star reconstructing array methods such as forEach, filter, map and reduce, and continue with different ones in separate files.
The first four methods (forEach, filter, map, and reduce) are done following Watch and Code "Testing" section (although I try the exercises before the videos, so differences are expected). Whatever follows next are exercises on my own.
Finished means it passes all the tests, not perfect code. There are some solutions I think could be better and refactored, and I will in due time.
I've compiled all of the methods so far in a file called rewriteLibrary.js. The library is being used in some of these methods as a way of not repeating myself, and putting the former defined methods to the test.
- Array.prototype.forEach --> finished
- Array.prototype.filter --> finished
- Array.prototype.map --> finished
- Array.prototype.reduce --> finished
- Array.prototype.find --> finished
- Array.prototype.findIndex --> finished
- Array.prototype.every --> finished
- Array.prototype.some --> finished
- Array.prototype.reduceRight --> in process
- Array.prototype.concat --> finished
- Array.prototype.indexOf --> finished
- Array.prototype.lastIndexOf --> finished
- Array.prototype.includes --> finished
- Array.prototype.slice --> finished
- Array.prototype.join --> finished
- Array.prototype.push --> finished
- Array.prototype.pop --> finished
- Array.prototype.shift --> finished
- Array.prototype.unshift --> finished
- Array.prototype.fill --> finished
- Array.prototype.reverse --> finished
- Array.prototype.copyWithin --> in process
- Array.prototype.sort
- Array.prototype.splice
- Array.prototype.from --> finished
- *arrayToObject --> finished
- *objectUnshift --> finished
- arrayToObject is a helper function that takes an array and returns an iterable object:
let array = ['a','b','c'];
let turnedIntoObject = arrayToObject(array);
// now turnedIntoObject is:
{0: 'a', 1: 'b', 2: 'c', index: 3};- objectUnshift is another method to unshift objects. Is integrated into unshift, so there is no need to call it by it's own.