Skip to content

Commit

Permalink
Fixed code style linting infra
Browse files Browse the repository at this point in the history
  • Loading branch information
amilajack committed Apr 19, 2018
1 parent fb06649 commit 40e6670
Show file tree
Hide file tree
Showing 64 changed files with 415 additions and 262 deletions.
4 changes: 1 addition & 3 deletions Binary/OnesInBinary.js
Expand Up @@ -12,7 +12,5 @@ export default function OnesInBinary(number: number): number {
binary[binary.length - 1 - pwr] = 1;
}

return binary.reduce(
(p: number, c: number): number => (c === 1 ? p + 1 : p)
);
return binary.reduce((p: number, c: number): number => (c === 1 ? p + 1 : p));
}
2 changes: 1 addition & 1 deletion CTCI/ch1/1.1.js
Expand Up @@ -7,7 +7,7 @@
*
* @flow
*/
export default function CheckHashAllUniqueChars(string: string): bool {
export default function CheckHashAllUniqueChars(string: string): boolean {
const set = new Set();

for (const char of string) {
Expand Down
2 changes: 1 addition & 1 deletion CTCI/ch1/1.5.js
@@ -1,5 +1,5 @@
// @flow
export default function OneAway(str1: string, str2: string): bool {
export default function OneAway(str1: string, str2: string): boolean {
const set1 = new Set(str1);
const set2 = new Set(str2);
const diffs = new Array(2);
Expand Down
7 changes: 1 addition & 6 deletions CTCI/ch1/1.7.js
Expand Up @@ -10,11 +10,6 @@ export default function RotateImage(img: number[][]): number[][] {
}
}

const img = [
[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4]
];
const img = [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]];

console.log(RotateImage(img));
12 changes: 5 additions & 7 deletions DataStructures/BTree.js
@@ -1,10 +1,10 @@
// @flow
class TreeNode {
keys: Array<number> = []
keys: Array<number> = [];

children: Array<TreeNode> = []
children: Array<TreeNode> = [];

parent: TreeNode
parent: TreeNode;

isLeaf() {
return this.children.length === 0;
Expand All @@ -18,7 +18,7 @@ class TreeNode {
export default class BTree {
root: TreeNode = new TreeNode();

t: number = 3
t: number = 3;

search(value: number, node: TreeNode = this.root): string {
// For each key of the node's keys
Expand All @@ -38,7 +38,7 @@ export default class BTree {
return '';
}

insert(value: number, node = this.root): bool {
insert(value: number, node = this.root): boolean {
// For each key of the node's keys
for (let i = 0; i < node.keys.length; i++) {
// If the value is less than the current key
Expand All @@ -59,7 +59,6 @@ export default class BTree {
split(node: TreeNode) {
// If the node doesn't need to be split, abort
if (node.children.length < this.t) {

} else {
// Otherwise, Split

Expand All @@ -68,4 +67,3 @@ export default class BTree {
}
}
}

14 changes: 7 additions & 7 deletions DataStructures/BinarySearchTree.js
@@ -1,18 +1,18 @@
// @flow
class Node {
data: number
data: number;

parent: Node
parent: Node;

left: Node
left: Node;

right: Node
right: Node;

constructor(data: number) {
this.data = data;
}

isLeaf(): bool {
isLeaf(): boolean {
return !this.left && !this.right;
}
}
Expand All @@ -26,7 +26,7 @@ export default class BinarySearchTree {
for (const item of items) this.add(item);
}

toArray(node?: Node): bool | void {
toArray(node?: Node): boolean | void {
if (!node) node = this.root;

if (node.isLeaf()) {
Expand All @@ -41,7 +41,7 @@ export default class BinarySearchTree {
if (node.right) this.toArray(node.right);
}

add(element: number, root?: Node): bool {
add(element: number, root?: Node): boolean {
let _root = root;

if (!this.root) {
Expand Down
18 changes: 9 additions & 9 deletions DataStructures/DAG.js
Expand Up @@ -45,17 +45,17 @@ export default class DAGAdjacencyList {
* @TODO: Prevent cycles
* @TODO: Add runtime
*/
breadthFirstSearch(target: Node): bool | Node {
breadthFirstSearch(target: Node): boolean | Node {
const queue = new Queue();

if (!this.adjacencyList[target.id]) {
return false;
}

// Push the node's immediate children of the first node
this.adjacencyList[0]
.children
.forEach(child => queue.push(this.adjacencyList[child]));
this.adjacencyList[0].children.forEach(child =>
queue.push(this.adjacencyList[child])
);

while (queue.size() > 0) {
const currentSearchNode = queue.pop();
Expand All @@ -64,9 +64,9 @@ export default class DAGAdjacencyList {
return currentSearchNode;
}

this.adjacencyList[currentSearchNode.id]
.children
.forEach(child => queue.push(this.adjacencyList[child]));
this.adjacencyList[currentSearchNode.id].children.forEach(child =>
queue.push(this.adjacencyList[child])
);
}

return false;
Expand All @@ -82,7 +82,7 @@ export default class DAGAdjacencyList {
* @param {number} node
* @param {number} target
*/
depthFirstSearch(node: Node, target: Node): bool {
depthFirstSearch(node: Node, target: Node): boolean {
const children = this.adjacencyList[node.id].children;

// Base case
Expand Down Expand Up @@ -130,5 +130,5 @@ export class DAGMatrix {
*
* Vertex matrixes are better for graphs that are more dense
*/
adjacencyMatrix: bool[][] = [];
adjacencyMatrix: boolean[][] = [];
}
20 changes: 10 additions & 10 deletions DataStructures/DoublyLinkedList.js
@@ -1,18 +1,18 @@
// @flow
export default class DoublyLinkedList {
head: Node
head: Node;

tail: Node
tail: Node;

head: Node
head: Node;

integrity = new Set()
integrity = new Set();

constructor() {
this.head = new Node({});
}

isEmpty(): bool {
isEmpty(): boolean {
return !!this.head;
}

Expand All @@ -33,7 +33,7 @@ export default class DoublyLinkedList {
/**
* Append node to end of list
*/
insert(data: any, begin?: Node): bool {
insert(data: any, begin?: Node): boolean {
const target: Node = begin || this.tail;
const node: Node = new Node(data);

Expand All @@ -47,16 +47,16 @@ export default class DoublyLinkedList {
}

class Node {
data: Object = {}
data: Object = {};

next: Node | bool = false
next: Node | boolean = false;

constructor(data: any = {}, next: Node | bool = false) {
constructor(data: any = {}, next: Node | boolean = false) {
this.data = data;
this.next = next;
}

hasNext(): bool {
hasNext(): boolean {
return this.next !== false;
}
}
25 changes: 11 additions & 14 deletions DataStructures/LinkedList.js
Expand Up @@ -10,17 +10,17 @@
//
// @flow
export default class LinkedList {
head: Node
head: Node;

tail: Node
tail: Node;

integrity = new Set()
integrity = new Set();

constructor() {
this.head = new Node({});
}

isEmpty(): bool {
isEmpty(): boolean {
return !!this.head;
}

Expand Down Expand Up @@ -49,10 +49,7 @@ export default class LinkedList {
let innerHead = this.head;

while (innerHead.hasNext()) {
if (
head.data > innerHead.data &&
head.data < innerHead.next.data
) {
if (head.data > innerHead.data && head.data < innerHead.next.data) {
// inserts
}
innerHead = innerHead.next;
Expand All @@ -77,7 +74,7 @@ export default class LinkedList {

insertAfter = this.insert;

insert(data: any, begin?: Node): bool {
insert(data: any, begin?: Node): boolean {
const node = new Node(data);
if (begin && this.integrity.has(node)) return false;
const headNext = (begin || this.head).next;
Expand All @@ -104,16 +101,16 @@ export default class LinkedList {
}

class Node {
data: number | string = 0
data: number | string = 0;

next: Node | bool = false
next: Node | boolean = false;

constructor(data: any = {}, next: Node | bool = false) {
constructor(data: any = {}, next: Node | boolean = false) {
this.data = data;
this.next = next;
}

hasNext(): bool {
hasNext(): boolean {
return this.next !== false;
}

Expand All @@ -129,7 +126,7 @@ class Node {
/**
* Append after node
*/
append(data: any): bool {
append(data: any): boolean {
const node = new Node(data);
const { next } = this;

Expand Down
4 changes: 1 addition & 3 deletions DataStructures/Map.js
Expand Up @@ -8,7 +8,6 @@
*/
import Hash from './Hash';


function HashMap() {
this.items = [];
this.mapLength = 50;
Expand All @@ -21,7 +20,7 @@ HashMap.prototype.insert = function insert(key: any, value: any): HashMap {
};

HashMap.prototype.all = function all(): any[] {
return this.items.filter((i: any): bool => !!i);
return this.items.filter((i: any): boolean => !!i);
};

/**
Expand All @@ -41,5 +40,4 @@ HashMap.prototype.remove = function remove(key: any): HashMap {
return this;
};


export default HashMap;
11 changes: 5 additions & 6 deletions DataStructures/MaxHeap.js
Expand Up @@ -14,7 +14,9 @@ export default class MaxHeap {

insert(node: number) {
this.nodes.push(node);
if (this.nodes.length === 1) { return; }
if (this.nodes.length === 1) {
return;
}
this._determineSwapWithParent(this.nodes.length - 1);
}

Expand Down Expand Up @@ -95,10 +97,7 @@ export default class MaxHeap {
const rightValue = this.nodes[rightIndex];

// If the root is smaller than any of its children
if (
leftValue > nodeValue ||
rightValue > nodeValue
) {
if (leftValue > nodeValue || rightValue > nodeValue) {
// If left child > right child, swap with root with left, vice versa
if (leftValue > rightValue) {
this.nodes[leftIndex] = nodeValue;
Expand All @@ -117,6 +116,6 @@ export default class MaxHeap {
}

getRight(nodeIndex: number) {
return nodeIndex === 0 ? 2 : (nodeIndex * 2) + 1;
return nodeIndex === 0 ? 2 : nodeIndex * 2 + 1;
}
}
6 changes: 3 additions & 3 deletions DataStructures/PriorityQueue.js
Expand Up @@ -9,12 +9,12 @@
import MaxHeap from '../DataStructures/MaxHeap';

export class PriorityNode<T> {
priority: number
data: T
priority: number;
data: T;
}

export default class PriorityQueue {
items: Array<PriorityNode>
items: Array<PriorityNode>;

constructor(items: Array<PriorityNode>) {
this.heap = new MaxHeap();
Expand Down
2 changes: 1 addition & 1 deletion DataStructures/Queue.js
Expand Up @@ -7,7 +7,7 @@
* @flow
*/
export default class Queue<T> {
items: T[]
items: T[];

constructor(items: T[] = []) {
this.items = items;
Expand Down

0 comments on commit 40e6670

Please sign in to comment.