Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selection sort #87

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
fe32bd2
Update diagrams.xml
StephenGrider Nov 10, 2017
6a389e5
Update diagrams.xml
StephenGrider Nov 10, 2017
35ac131
bst
StephenGrider Nov 10, 2017
a621483
Update diagrams.xml
StephenGrider Nov 10, 2017
5ba6869
Update diagrams.xml
StephenGrider Nov 10, 2017
a14b1d9
Update diagrams.xml
StephenGrider Nov 10, 2017
cf04144
bst
StephenGrider Nov 10, 2017
ee47464
validate
StephenGrider Nov 10, 2017
01b1caa
validate
StephenGrider Nov 10, 2017
f86fca8
validate
StephenGrider Nov 11, 2017
72eeb9f
Update diagrams.xml
StephenGrider Nov 11, 2017
2353e63
Update diagrams.xml
StephenGrider Nov 11, 2017
7eaed0d
events
StephenGrider Nov 11, 2017
9126229
Update diagrams.xml
StephenGrider Nov 13, 2017
8978c69
Update diagrams.xml
StephenGrider Nov 13, 2017
dced4eb
Update diagrams.xml
StephenGrider Nov 13, 2017
ffb0331
Update diagrams.xml
StephenGrider Nov 13, 2017
6325ced
Update diagrams.xml
StephenGrider Nov 13, 2017
abb5dbf
Update diagrams.xml
StephenGrider Nov 13, 2017
90f3856
Update diagrams.xml
StephenGrider Nov 13, 2017
c1caa41
Update diagrams.xml
StephenGrider Nov 13, 2017
e17a68e
Update diagrams.xml
StephenGrider Nov 13, 2017
39d4d86
Update diagrams.xml
StephenGrider Nov 13, 2017
bb6e2e5
Update diagrams.xml
StephenGrider Nov 13, 2017
1ef9c66
events
StephenGrider Nov 13, 2017
1a349ff
Update diagrams.xml
StephenGrider Nov 13, 2017
cab00ec
bst
StephenGrider Nov 13, 2017
654f854
Added diagrams.xml
StephenGrider Nov 13, 2017
6c9cb78
Update diagrams.xml
StephenGrider Nov 13, 2017
b66d697
bst
StephenGrider Nov 13, 2017
26c70db
sort
StephenGrider Nov 13, 2017
256b794
Update diagrams.xml
StephenGrider Nov 13, 2017
a1d5bb9
Update diagrams.xml
StephenGrider Nov 13, 2017
1d4583e
Update diagrams.xml
StephenGrider Nov 13, 2017
d094a4f
Update diagrams.xml
StephenGrider Nov 14, 2017
a84ba71
Update diagrams.xml
StephenGrider Nov 14, 2017
0a1072f
Update diagrams.xml
StephenGrider Nov 14, 2017
a620cc6
Update diagrams.xml
StephenGrider Nov 14, 2017
36488b3
Update diagrams.xml
StephenGrider Nov 14, 2017
1f0dfd5
completed exercises
StephenGrider Nov 15, 2017
f065645
Merge branch 'master' of github.com:StephenGrider/AlgoCasts
StephenGrider Nov 15, 2017
101dcb6
Create README.md
StephenGrider Nov 15, 2017
408cf18
Update test.js
StephenGrider Nov 28, 2017
46139e9
Update package.json
StephenGrider Aug 1, 2018
3608c82
Create LICENSE
StephenGrider Sep 14, 2018
60587af
Merge pull request #34 from StephenGrider/add-license-1
StephenGrider Sep 14, 2018
8aa9aff
Update test.js
StephenGrider Dec 3, 2018
32b9e8b
Update README.md
StephenGrider Dec 3, 2018
f0cce74
Update test.js
StephenGrider Dec 3, 2018
f053cd1
Update index.js
StephenGrider Dec 12, 2018
15ecab9
Done
Miss-Cheese Mar 25, 2020
69afaf7
Done
Miss-Cheese Mar 27, 2020
8d8a167
Done
Miss-Cheese Mar 27, 2020
1980bc3
Bubble sort done
Miss-Cheese Apr 13, 2020
1cd8b20
Selection sort done
Miss-Cheese Apr 13, 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
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# AlgoCasts

Companion repo to a course on Udemy.com
13 changes: 0 additions & 13 deletions clean/anagrams/index.js

This file was deleted.

12 changes: 0 additions & 12 deletions clean/capitalize/index.js

This file was deleted.

13 changes: 0 additions & 13 deletions clean/chunk/index.js

This file was deleted.

13 changes: 0 additions & 13 deletions clean/fib/index.js

This file was deleted.

9 changes: 0 additions & 9 deletions clean/linkedlist/index.js

This file was deleted.

20 changes: 0 additions & 20 deletions clean/matrix/index.js

This file was deleted.

10 changes: 0 additions & 10 deletions clean/maxchar/index.js

This file was deleted.

19 changes: 0 additions & 19 deletions clean/pyramid/index.js

This file was deleted.

19 changes: 0 additions & 19 deletions clean/qfroms/index.js

This file was deleted.

11 changes: 0 additions & 11 deletions clean/reversestring/index.js

This file was deleted.

22 changes: 0 additions & 22 deletions clean/steps/index.js

This file was deleted.

12 changes: 0 additions & 12 deletions clean/vowels/index.js

This file was deleted.

51 changes: 51 additions & 0 deletions completed_exercises/anagrams/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// --- Directions
// Check to see if two provided strings are anagrams of eachother.
// One string is an anagram of another if it uses the same characters
// in the same quantity. Only consider characters, not spaces
// or punctuation. Consider capital letters to be the same as lower case
// --- Examples
// anagrams('rail safety', 'fairy tales') --> True
// anagrams('RAIL! SAFETY!', 'fairy tales') --> True
// anagrams('Hi there', 'Bye there') --> False

function anagrams(stringA, stringB) {
return cleanString(stringA) === cleanString(stringB);
}

function cleanString(str) {
return str
.replace(/[^\w]/g, '')
.toLowerCase()
.split('')
.sort()
.join('');
}

module.exports = anagrams;

// function anagrams(stringA, stringB) {
// const aCharMap = buildCharMap(stringA);
// const bCharMap = buildCharMap(stringB);
//
// if (Object.keys(aCharMap).length !== Object.keys(bCharMap).length) {
// return false;
// }
//
// for (let char in aCharMap) {
// if (aCharMap[char] !== bCharMap[char]) {
// return false;
// }
// }
//
// return true;
// }
//
// function buildCharMap(str) {
// const charMap = {};
//
// for (let char of str.replace(/[^\w]/g, '').toLowerCase()) {
// charMap[char] = charMap[char] + 1 || 1;
// }
//
// return charMap;
// }
File renamed without changes.
49 changes: 49 additions & 0 deletions completed_exercises/bst/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// --- Directions
// 1) Implement the Node class to create
// a binary search tree. The constructor
// should initialize values 'data', 'left',
// and 'right'.
// 2) Implement the 'insert' method for the
// Node class. Insert should accept an argument
// 'data', then create an insert a new node
// at the appropriate location in the tree.
// 3) Implement the 'contains' method for the Node
// class. Contains should accept a 'data' argument
// and return the Node in the tree with the same value.
// If the value isn't in the tree return null.

class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}

insert(data) {
if (data < this.data && this.left) {
this.left.insert(data);
} else if (data < this.data) {
this.left = new Node(data);
} else if (data > this.data && this.right) {
this.right.insert(data);
} else if (data > this.data) {
this.right = new Node(data);
}
}

contains(data) {
if (this.data === data) {
return this;
}

if (this.data < data && this.right) {
return this.right.contains(data);
} else if (this.data > data && this.left) {
return this.left.contains(data);
}

return null;
}
}

module.exports = Node;
41 changes: 41 additions & 0 deletions completed_exercises/bst/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const Node = require('./index');

test('Node is a constructor', () => {
expect(typeof Node.prototype.constructor).toEqual('function');
});

test('Node can insert correctly', () => {
const node = new Node(10);
node.insert(5);
node.insert(15);
node.insert(17);

expect(node.left.data).toEqual(5);
expect(node.right.data).toEqual(15);
expect(node.right.right.data).toEqual(17);
});

test('Contains returns node with the same data', () => {
const node = new Node(10);
node.insert(5);
node.insert(15);
node.insert(20);
node.insert(0);
node.insert(-5);
node.insert(3);

const three = node.left.left.right;
expect(node.contains(3)).toEqual(three);
});

test('Contains returns null if value not found', () => {
const node = new Node(10);
node.insert(5);
node.insert(15);
node.insert(20);
node.insert(0);
node.insert(-5);
node.insert(3);

expect(node.contains(9999)).toEqual(null);
});
34 changes: 34 additions & 0 deletions completed_exercises/capitalize/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// --- Directions
// Write a function that accepts a string. The function should
// capitalize the first letter of each word in the string then
// return the capitalized string.
// --- Examples
// capitalize('a short sentence') --> 'A Short Sentence'
// capitalize('a lazy fox') --> 'A Lazy Fox'
// capitalize('look, it is working!') --> 'Look, It Is Working!'

function capitalize(str) {
let result = str[0].toUpperCase();

for (let i = 1; i < str.length; i++) {
if (str[i - 1] === ' ') {
result += str[i].toUpperCase();
} else {
result += str[i];
}
}

return result;
}

module.exports = capitalize;

// function capitalize(str) {
// const words = [];
//
// for (let word of str.split(' ')) {
// words.push(word[0].toUpperCase() + word.slice(1));
// }
//
// return words.join(' ');
// }
File renamed without changes.
Loading