Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
4c101fb
added challenge 2
morgantatums Oct 3, 2019
4a18ce2
updated top level readme table of contents
morgantatums Oct 3, 2019
dd4a2c6
updated readme
morgantatums Oct 3, 2019
1b024ad
added code
morgantatums Oct 4, 2019
2546c80
working on test file
morgantatums Oct 4, 2019
29fd0d9
added uml
morgantatums Oct 4, 2019
c012a13
updated readme
morgantatums Oct 4, 2019
dee1727
fixed testing
morgantatums Oct 5, 2019
90ff151
fixed lint error
morgantatums Oct 5, 2019
cbd1b98
added basic files
morgantatums Oct 5, 2019
7857a03
added code and test
morgantatums Oct 5, 2019
9b717b2
updated readme
morgantatums Oct 5, 2019
de537cd
added comments to js file
morgantatums Oct 5, 2019
6961567
added UML
morgantatums Oct 6, 2019
dd4ef6e
fixed readme path
morgantatums Oct 8, 2019
dc11cc1
updated repo for 5
morgantatums Oct 16, 2019
7a76832
added insert before function and tests
morgantatums Oct 18, 2019
953a296
finished final
morgantatums Oct 18, 2019
991741f
updated readme
morgantatums Oct 18, 2019
71d5162
updated reamde
morgantatums Oct 21, 2019
332db58
added starter
morgantatums Oct 24, 2019
89384fc
completed function, working on tests
morgantatums Oct 24, 2019
bf1e12c
completed tests
morgantatums Oct 24, 2019
a2a37b4
fixed folder name
morgantatums Oct 26, 2019
63ef93f
added starter code
morgantatums Oct 26, 2019
af2a9da
finished most tests
morgantatums Oct 29, 2019
a05c28b
completed functions
morgantatums Oct 29, 2019
151cd5c
updated readme
morgantatums Oct 29, 2019
e7b0a11
turned off other tests
morgantatums Nov 2, 2019
1cd5936
updated readme
morgantatums Nov 2, 2019
80dae55
tried to fix lint
morgantatums Nov 2, 2019
d85e915
added travis to readme
morgantatums Nov 2, 2019
dfe56de
started on challenge
morgantatums Nov 7, 2019
dc860e0
finished final functions
morgantatums Nov 8, 2019
7897aab
finished readme
morgantatums Nov 8, 2019
b05bccb
updated travis url
morgantatums Nov 8, 2019
83fe781
updated readme
morgantatums Nov 8, 2019
765e493
set up files
morgantatums Nov 12, 2019
9669851
added some additional code
morgantatums Nov 15, 2019
3a6a0e8
added binary search tree
morgantatums Nov 22, 2019
fb2f13d
set up repo & file structure
morgantatums Dec 13, 2019
4726426
added passing test
morgantatums Dec 13, 2019
62991d1
fixed readme links
morgantatums Dec 13, 2019
5f8f11b
finished most but length of 10 & invalid parameter
morgantatums Dec 17, 2019
0d943a8
updated readme
morgantatums Dec 17, 2019
5ed85f8
added starter files
morgantatums Dec 20, 2019
f8e200b
added PR
morgantatums Dec 20, 2019
4682287
added tests & code
morgantatums Jan 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Data-Structures/LinkList/__tests__/linked-list.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const LinkList = require('../linked-list.js');

xdescribe('Test', () => {
// How might we repeat this to check on types?
it('true', ()=>{
expect(LinkList).toBeTruthy();
});
});
Empty file.
22 changes: 22 additions & 0 deletions Data-Structures/LinkList/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Singly Linked List

<!-- Short summary or background information -->

## Challenge
Write tests to prove the following functionality:

* Can successfully instantiate an empty linked list
* Can properly insert into the linked list
* The head property will properly point to the first node in the linked list
* Can properly insert multiple nodes into the linked list
* Will return true when finding a value within the linked list that exists
* Will return false when searching for a value in the linked list that does not exist
* Can properly return a collection of all the values that exist in the linked list

## Approach & Efficiency

<!-- What approach did you take? Why? What is the Big O space/time for this approach? -->

## API

<!-- Description of each method publicly available to your Linked List -->
22 changes: 22 additions & 0 deletions Data-Structures/Sorting/InsertionSort/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Insertion Sort

## Links

- [Link to Pull Request](https://github.com/morgan-401-advanced-javascript/data-structures-and-algorithms/pull/15)
- [Link to Travis](https://travis-ci.com/morgan-401-advanced-javascript/data-structures-and-algorithms)

## Whiteboard / Drawing

<!-- Photo of your whiteboard or drawing -->

## Challenge

Write a function called `insertionSort`, which takes an array of numbers and returns a sorted array after using the Insertion Sort algorithm. Do not mutate (change) the array given to you as a parameter.

## Approach & Efficiency

O(n) since we do not mutate the array in place and create a duplicate array that we manipulate

## API

`InsertionSort(array)` function that takes in an array as a parameter
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';
const InsertionSort = require('../insertion-sort');

describe('Test', () => {
it('true', ()=>{
expect(true).toBeTruthy();
});
});

// Sort array of length 1
xdescribe('Insertion Sort Tests', () => {
it('Sort array of length 1', ()=>{
let array = [ 13 ];
let sortedArray = InsertionSort(array);
console.log(sortedArray);
expect(sortedArray).toEqual([13]);
});
// Sort array of length 2
it('Sort array of length 2', ()=>{
let array = [13, 5];
let sortedArray = InsertionSort(array);
expect(sortedArray).toEqual([5, 13]);
});
// Sort array of length 10
it('Sort array of length 10', ()=>{
let array = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
let sortedArray = InsertionSort(array);
expect(sortedArray).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
});
// Incorrect parameter error handling
xit('Incorrect parameter error handling', ()=>{
let sortedArray = InsertionSort();
expect(sortedArray).toBe('Incorrect parameter');
});
// Not an array
it('Not an array', ()=>{
let array = 'animal';
let sortedArray = InsertionSort(array);
expect(sortedArray).toBe('Not an array');
});
// Empty array
it('Empty array', ()=>{
let array = [];
console.log(array[0]);
let sortedArray = InsertionSort(array);
expect(sortedArray).toBe('Empty array');
});
// Array with non-numerical values
it('Array with non-numerical values', ()=>{
let array = ['blue'];
let sortedArray = InsertionSort(array);
expect(sortedArray).toBe('Array with non-numerical values');
});
});
33 changes: 33 additions & 0 deletions Data-Structures/Sorting/InsertionSort/insertion-sort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

function insertionSort(array) {
let answer =[...array];
if(Array.isArray(array) != true){
return('Not an array');
}
if(array.length === 0){
return('Empty array');
}
if(typeof array[0] != 'number'){
return('Array with non-numerical values');
}
else{
let i = 0;
while(i <= answer.length){
let j =1;
while(j > 0){
if(answer[j-1] > answer[j]){
let temp = answer[j];
answer[j] = answer[j-1];
answer[j-1] = temp;
}
j = j-1;
}
i++;
}
return answer;
}

}

module.exports = insertionSort;
24 changes: 24 additions & 0 deletions Data-Structures/Sorting/MergeSort/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Links

- [Link to Pull Request](https://github.com/morgan-401-advanced-javascript/data-structures-and-algorithms/pull/16)
- [Link to Travis](https://travis-ci.com/morgan-401-advanced-javascript/data-structures-and-algorithms)


## Whiteboard / Drawing

<!-- Photo of your whiteboard or drawing -->

## Challenge

Write a function called mergeSort, which takes an array of numbers and returns a sorted array after using the Merge Sort algorithm. Do not mutate (change) the array given to you as a parameter.

## Approach & Efficiency

Best case scenario is Big O(nlog(n))
space is Big O(n)

## API

`mergeSort(arr)` takes in an unsorted array and will return a sorted array
`sort(temp, sIndx, eIndx)`
`merge(arr, sIndx, mid, eIndx)`
45 changes: 45 additions & 0 deletions Data-Structures/Sorting/MergeSort/__tests__/merge-sort.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const mergeSort = require('../merge-sort');


describe('Test', () => {
it('true', ()=>{
expect(true).toBeTruthy();
});
});


// Incorrect parameter error handling
describe('Incorrect parameter error handling', () => {
// Not an array
it('Not an array', ()=>{
let testArray = {};
expect( mergeSort(testArray)).toBe('Not an array');
});
// Empty array
it('Empty array', ()=>{
let testArray = [];
expect( mergeSort(testArray)).toBe('Empty array');
});
// Array with non-numerical values
it('Array with non-numerical values', ()=>{
let testArray = ['a', 'c'];
expect( mergeSort(testArray)).toBe('Not an array of only numerical values');
});
});
describe('Sorting tests', () => {
// Sort array of length 1
it('Sort array of length 1', ()=>{
let testOne = [42];
expect(mergeSort(testOne)).toEqual([42]);
});
// Sort array of length 2
it('Sort array of length 2', ()=>{
let testOne = [4, 2];
expect(mergeSort(testOne)).toEqual([2, 4]);
});
// Sort array of length 10
it('Sort array of length 10', ()=>{
let testOne = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
expect(mergeSort(testOne)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
});
});
47 changes: 47 additions & 0 deletions Data-Structures/Sorting/MergeSort/merge-sort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

function mergeSort(arr) {
if(Array.isArray(arr) === false) {
return 'Not an array';
}
if(!arr.every(el => typeof el === 'number')) {
return 'Not an array of only numerical values';
}
if(!arr.length) {
return 'Empty array';
}
if(arr.length === 1) {
return arr;
}
let temp = [...arr];

function sort(temp, sIndx, eIndx) {
if(sIndx >= eIndx) {
return;
}
let mid = Math.floor((sIndx + eIndx)/2);
sort(temp, sIndx, mid);
sort(temp, mid + 1, eIndx);
merge(temp, sIndx, mid, eIndx);
}
sort(temp, 0, temp.length - 1);
return temp;
}

function merge(arr, sIndx, mid, eIndx) {
let merged = [];
let j = mid +1;
for(let i = sIndx; i <= mid; i++){
while(arr[i] > arr[j] && j <= eIndx) {
merged.push(arr[j]);
j++;
}

merged.push(arr[i]);
}
for(let i = 0; i < merged.length; i++) {
arr[sIndx + i] = merged[i];
}
}

module.exports = mergeSort;
Loading