-/*
-#animatedElem {
- position: absolute;
- width: 20px;
- height: 20px;
- background: #ff6600;
-}
-*/
-
-
-var elem = document.getElementById("animatedElem"),
- left = 0,
- lastFrame = +new Date,
- timer;
-// Move the element on the right at ~600px/s
-timer = setInterval(function() {
- var now = +new Date,
- deltaT = now - lastFrame;
- elem.style.left = ( left += 10 * deltaT / 16 ) + "px";
- lastFrame = now;
- // clear the timer at 400px to stop the animation
- if ( left > 400 ) {
- clearInterval( timer );
- }
-}, 16);
diff --git a/problems/filterArrayBasedOnAnotherArray.js b/problems/filterArrayBasedOnAnotherArray.js
deleted file mode 100644
index 28422d9..0000000
--- a/problems/filterArrayBasedOnAnotherArray.js
+++ /dev/null
@@ -1,22 +0,0 @@
-let items = [
- {color: 'red', type: 'tv', age: 18},
- {color: 'silver', type: 'phone', age: 20},
- {color: 'blue', type: 'phone', age: 20},
- {color: 'green', type: 'phone', age: 20}
-];
-
-let excludes = [
- {k: 'color', v: 'silver'},
- {k: 'type', v: 'tv'},
-];
-
-
-let newItems = items.reduce((acc, item) => {
- let result = excludes.some(exclude => item[exclude['k']] === exclude['v']);
- if (!result) {
- acc.push(item);
- }
- return acc;
-}, []);
-
-console.log(newItems);
diff --git a/problems/flattenObject.js b/problems/flattenObject.js
deleted file mode 100644
index 5df53e2..0000000
--- a/problems/flattenObject.js
+++ /dev/null
@@ -1,43 +0,0 @@
-let obj = {
- "a": {
- "b": {
- "c": 12,
- "d": "Hello World",
- "e": null
- },
- "f": [1,2,3]
- }
-};
-
-const flatten = (obj, parentkey) => {
- return Object.keys(obj).reduce((acc, key) => {
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
- let val = obj[key];
- if (typeof val === "object" && !Array.isArray(val) && val != null) { // != will catch undefined or null
- let flat = flatten(val, key);
- if (parentkey) {
- for (let i in flat) {
- let k = `${parentkey}/${i}`;
- acc[k] = flat[i];
- }
- } else {
- acc = flat;
- }
- } else {
- let prop = parentkey ? `${parentkey}/${key}` : key;
- acc[prop] = val;
- }
- }
- return acc;
- }, {});
-};
-
-
-console.log(flatten(obj));
-
-// {
-// a/b/c: 12,
-// a/b/d: "Hello World",
-// a/b/e: null,
-// a/f: [1, 2, 3]
-// }
diff --git a/problems/graph.js b/problems/graph.js
deleted file mode 100644
index 6cf6472..0000000
--- a/problems/graph.js
+++ /dev/null
@@ -1,166 +0,0 @@
-class Graph {
- constructor() {
- this.vertices = [];
- this.edges = {};
- this.numberOfEdges = 0;
- }
-
- addVertex(vertex) {
- this.vertices.push(vertex);
- this.edges[vertex] = [];
- }
-
- addEdge(vertex1, vertex2) {
- this.edges[vertex1].push(vertex2);
- this.edges[vertex2].push(vertex1);
- this.numberOfEdges++;
- }
-
- removeVertex(vertex) {
- const index = this.vertices.indexOf(vertex);
- if(~index) {
- this.vertices.splice(index, 1);
- }
- while(this.edges[vertex].length) {
- const adjacentVertex = this.edges[vertex].pop();
- this.removeEdge(adjacentVertex, vertex);
- }
- }
-
- removeEdge(vertex1, vertex2) {
- const index1 = this.edges[vertex1] ? this.edges[vertex1].indexOf(vertex2) : -1;
- const index2 = this.edges[vertex2] ? this.edges[vertex2].indexOf(vertex1) : -1;
- if(~index1) {
- this.edges[vertex1].splice(index1, 1);
- this.numberOfEdges--;
- }
- if(~index2) {
- this.edges[vertex2].splice(index2, 1);
- }
- }
-
- size() {
- return this.vertices.length;
- }
-
- relations() {
- return this.numberOfEdges;
- }
-
- traverseDFS(vertex, fn) {
- if(!~this.vertices.indexOf(vertex)) {
- return console.log('Vertex not found');
- }
- const visited = {};
- this._traverseDFS(vertex, visited, fn);
- }
-
- _traverseDFS(vertex, visited, fn) {
- visited[vertex] = true;
- if (typeof fn === "function") {
- fn(vertex);
- }
- this.edges[vertex].forEach(adjVertex => {
- if(!visited[adjVertex]) {
- this._traverseDFS(adjVertex, visited, fn);
- }
- });
- }
-
- traverseBFS(vertex, fn) {
- if(!~this.vertices.indexOf(vertex)) {
- return console.log('Vertex not found');
- }
- const queue = [vertex];
- const visited = {[vertex] : true};
-
- while(queue.length) {
- vertex = queue.shift();
- if (typeof fn === "function") {
- fn(vertex);
- }
- this.edges[vertex].forEach(vEdge => {
- if(!visited[vEdge]) {
- visited[vEdge] = true;
- queue.push(vEdge);
- }
- });
- }
- }
-
- pathFromTo(vertexSource, vertexDestination) {
- if(!~this.vertices.indexOf(vertexSource) || this.vertices.indexOf(vertexDestination) === -1) {
- return console.log('Vertex not found');
- }
- const queue = [vertexSource];
- const visited = {[vertexSource]: true };
- const paths = {};
-
- while(queue.length) {
- const vertex = queue.shift();
- this.edges[vertex].forEach(vEdge => {
- if(!visited[vEdge]) {
- visited[vEdge] = true;
- queue.push(vEdge);
- // save paths between vertices
- paths[vEdge] = vertex;
- }
- });
- }
-
- let current = vertexDestination;
- const path = [];
- while (current) {
- path.push(current);
- current = paths[current];
- }
- return path.join('-');
- }
-
- print() {
- console.log(this.vertices.map(function(vertex) {
- return (`${vertex} -> ${this.edges[vertex].join(', ')}`).trim();
- }, this).join(' | '));
- }
-}
-
-const graph = new Graph();
-graph.addVertex(1);
-graph.addVertex(2);
-graph.addVertex(3);
-graph.addVertex(4);
-graph.addVertex(5);
-graph.addVertex(6);
-graph.print(); // 1 -> | 2 -> | 3 -> | 4 -> | 5 -> | 6 ->
-graph.addEdge(1, 2);
-graph.addEdge(1, 5);
-graph.addEdge(2, 3);
-graph.addEdge(2, 5);
-graph.addEdge(3, 4);
-graph.addEdge(4, 5);
-graph.addEdge(4, 6);
-graph.print(); // 1 -> 2, 5 | 2 -> 1, 3, 5 | 3 -> 2, 4 | 4 -> 3, 5, 6 | 5 -> 1, 2, 4 | 6 -> 4
-console.log('graph size (number of vertices):', graph.size()); // => 6
-console.log('graph relations (number of edges):', graph.relations()); // => 7
-graph.traverseDFS(1, vertex => { console.log(vertex); }); // => 1 2 3 4 5 6
-console.log('---');
-graph.traverseBFS(1, vertex => { console.log(vertex); }); // => 1 2 5 3 4 6
-graph.traverseDFS(0, vertex => { console.log(vertex); }); // => 'Vertex not found'
-graph.traverseBFS(0, vertex => { console.log(vertex); }); // => 'Vertex not found'
-console.log('path from 6 to 1:', graph.pathFromTo(6, 1)); // => 6-4-5-1
-console.log('path from 3 to 5:', graph.pathFromTo(3, 5)); // => 3-2-5
-graph.removeEdge(1, 2);
-graph.removeEdge(4, 5);
-graph.removeEdge(10, 11);
-console.log('graph relations (number of edges):', graph.relations()); // => 5
-console.log('path from 6 to 1:', graph.pathFromTo(6, 1)); // => 6-4-3-2-5-1
-graph.addEdge(1, 2);
-graph.addEdge(4, 5);
-console.log('graph relations (number of edges):', graph.relations()); // => 7
-console.log('path from 6 to 1:', graph.pathFromTo(6, 1)); // => 6-4-5-1
-graph.removeVertex(5);
-console.log('graph size (number of vertices):', graph.size()); // => 5
-console.log('graph relations (number of edges):', graph.relations()); // => 4
-console.log('path from 6 to 1:', graph.pathFromTo(6, 1)); // => 6-4-3-2-1
-graph.traverseDFS(1, (v) => console.log(`traverse DFS ${v}`) );
-graph.traverseBFS(1, (v) => console.log(`traverse BFS ${v}`) );
diff --git a/problems/layout.md b/problems/layout.md
deleted file mode 100644
index ec0f0d9..0000000
--- a/problems/layout.md
+++ /dev/null
@@ -1,4 +0,0 @@
-[FlexBox](https://philipwalton.github.io/solved-by-flexbox/demos/holy-grail/) - Holy grail layout using FlexBox
-[Grid](https://bitsofco.de/holy-grail-layout-css-grid/) - Holy grail layout using grid
-[Learn flexbox](http://flexboxfroggy.com/) - flex box froggy
-[Learn CSS Grid](https://cssgridgarden.com/) - CSS grid garden
diff --git a/problems/lengthOfLongestSubString.js b/problems/lengthOfLongestSubString.js
deleted file mode 100644
index b92c0b9..0000000
--- a/problems/lengthOfLongestSubString.js
+++ /dev/null
@@ -1,23 +0,0 @@
-const lengthOfLongestSubstring = function(s) {
-
- let map = {}
- let start = 0
- let maxLen = 0
- let arr = s.split('')
-
- for (let i=0; i < s.length; i++) {
- let current = map[arr[i]];
- if (current != null && start <= current) {
- start = current + 1;
- } else {
- maxLen = Math.max(maxLen, i - start + 1)
- }
- map[arr[i]] = i;
- }
-
- return maxLen;
-};
-
-console.log(lengthOfLongestSubstring("abcabcbb")); //3
-console.log(lengthOfLongestSubstring("cccc")); //1
-console.log(lengthOfLongestSubstring("umesh")); 5
diff --git a/problems/maxSubArray.js b/problems/maxSubArray.js
deleted file mode 100644
index 1deda7d..0000000
--- a/problems/maxSubArray.js
+++ /dev/null
@@ -1,10 +0,0 @@
-const maxSubArray = (nums) => {
- let currentSum = 0;
- return nums.reduce((acc, item) => {
- currentSum = Math.max(currentSum+item, 0);
- return Math.max(acc, currentSum)
- }, 0);
-};
-
-console.log(maxSubArray([-2,1,-3,4,-1,2,1,-5,4])) // 6
-console.log(maxSubArray([4,-1,3,1])) // 7
diff --git a/problems/median_of_arr.js b/problems/median_of_arr.js
deleted file mode 100644
index 8fbbbc0..0000000
--- a/problems/median_of_arr.js
+++ /dev/null
@@ -1,24 +0,0 @@
-const median = (arr) => {
- if (!Array.isArray(arr)) {
- return null; // or throw error;
- }
- if (arr.length === 0) {
- return null;
- }
-
- let cloneArr = arr.slice();
- let sortedArr = cloneArr.sort((a, b) => a - b);
-
- let mid = Math.floor((0, sortedArr.length - 1) / 2);
- if (sortedArr.length % 2 === 0) {
- return (sortedArr[mid] + sortedArr[mid + 1]) / 2;
- }
- return sortedArr[mid];
-};
-
-
-let arr = [3,8,9,1,5,7,9,21];
-console.log(median(arr)); // 7.5
-
-let arr1 = [1,2,4,3,5];
-console.log(median(arr1)); // 3
diff --git a/problems/mergeOverlappingInterval.js b/problems/mergeOverlappingInterval.js
deleted file mode 100644
index b9d11fc..0000000
--- a/problems/mergeOverlappingInterval.js
+++ /dev/null
@@ -1,25 +0,0 @@
-const mergeIntervals = (arr) => {
- if (arr == null || arr.length < 2) {
- return arr;
- }
-
- arr.sort((a, b) => a[0] - b[0]);
-
- return arr.reduce((acc, cur) => {
- let last = acc.pop()
- if (last) {
- if (last[1] > cur[0]) {
- let newLast = [last[0], cur[1]];
- acc.push(newLast);
- } else {
- acc.push(last, cur);
- }
- } else {
- acc.push(cur);
- }
- return acc;
- }, []);
-};
-
-console.log(mergeIntervals( [[1,3],[2,6],[8,10],[15,18]])); //[[1, 6], [8, 10], [15, 18]]
-console.log(mergeIntervals([[1,4],[3,5],[2,4],[7,10]])); // [[1, 5], [7, 10]]
diff --git a/problems/overlapRectangle.js b/problems/overlapRectangle.js
deleted file mode 100644
index ece2cce..0000000
--- a/problems/overlapRectangle.js
+++ /dev/null
@@ -1,26 +0,0 @@
-class Rectangle {
- constructor(x, y, width, height) {
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
- }
-
- isOverlapping(rect2) {
- return (this.x < (rect2.x + rect2.width) &&
- (this.x + this.width) > rect2.x &&
- this.y < (rect2.y + rect2.height) &&
- (this.y + this.height) > rect2.y
- );
- }
-}
-
-const rect1 = new Rectangle(250, 250, 150,100);
-const rect2 = new Rectangle(100, 100, 300, 200);
-
-const rect3 = new Rectangle(450, 450, 150,100);
-
-
-console.log(rect1.isOverlapping(rect2)); // true
-
-console.log(rect2.isOverlapping(rect3)); // false
diff --git a/problems/secondLargestInArray.js b/problems/secondLargestInArray.js
deleted file mode 100644
index e046814..0000000
--- a/problems/secondLargestInArray.js
+++ /dev/null
@@ -1,18 +0,0 @@
-const secondLargest = (arr) => {
- //return arr.sort((a, b) => a - b)[arr.length -2]; // different solution
- let largest = -1;
- let secondLargest = -1;
- arr.forEach(el => {
- if (el > largest) {
- let temp = largest;
- largest = el;
- secondLargest = temp;
- } else if (el > secondLargest) {
- secondLargest = el;
- }
- });
-
- return secondLargest;
-}
-
-console.log(secondLargest([1,10,2,9])) // 9
diff --git a/problems/sequentialPromiseExecution.js b/problems/sequentialPromiseExecution.js
deleted file mode 100644
index b6cf497..0000000
--- a/problems/sequentialPromiseExecution.js
+++ /dev/null
@@ -1,9 +0,0 @@
-"use strict";
-
-return tasks.reduce((promiseChain, currentTask) => {
- return promiseChain.then(chain =>
- currentTask.then(result => [...chain, result]);
- );
-}, Promise.resolve([])).then(arrayOfResults => {
- ....
-});
diff --git a/problems/sortedArrayToBST.js b/problems/sortedArrayToBST.js
deleted file mode 100644
index 92a2947..0000000
--- a/problems/sortedArrayToBST.js
+++ /dev/null
@@ -1,22 +0,0 @@
-"use strict";
-class Node {
- constructor(value){
- this.value = value;
- this.left = this.right = null;
- }
-}
-const sortedArrayToBST = (nums) => {
- let sortedArrayToBSTRec = (nums, start, end) => {
- if (start > end) {
- return null
- }
- let mid = Math.floor((start + end) / 2)
- let root = new Node(nums[mid])
- root.left = sortedArrayToBSTRec(nums, start, mid - 1)
- root.right = sortedArrayToBSTRec(nums, mid + 1, end)
- return root
- }
- return sortedArrayToBSTRec(nums, 0, nums.length - 1)
-};
-
-console.log(sortedArrayToBST([1,2,3,4,5,6,7]))
diff --git a/problems/stringPermutations.js b/problems/stringPermutations.js
deleted file mode 100644
index bf2174b..0000000
--- a/problems/stringPermutations.js
+++ /dev/null
@@ -1,46 +0,0 @@
-const strPermutations = str => {
- if (str.length < 2) {
- return str; // This is our break condition
- }
-
- let permutations = []; // This array will hold our permutations
-
- for (let i = 0, len = str.length; i < len; i++) {
- let char = str[i];
- let remainingString = `${str.slice(0,i)}${str.slice(i+1)}`;
- for (let subPermutation of strPermutations(remainingString)) {
- permutations.push(char + subPermutation);
- }
- }
- return permutations;
-}
-
-console.log(strPermutations("abcd"));
-// ["abcd", "abdc", "acbd", "acdb", "adbc", "adcb", "bacd", "badc", "bcad", "bcda", "bdac", "bdca", "cabd",
-// "cadb", "cbad", "cbda", "cdab", "cdba", "dabc", "dacb", "dbac", "dbca", "dcab", "dcba"]
-
-// Permuation of an array
-
-function permutation(input) {
- let outputs = [[input[0]]];
- for (let i = 1; i < input.length; i++) {
- let current = [];
- for (let j = 0; j < outputs.length; j++) {
- let base = outputs[j];
- for (let k = 0; k <= base.length; k++) {
- let temp = base.slice();
- temp.splice(k, 0, input[i]);
- current.push(temp);
- }
- }
- outputs = current;
- }
- return outputs;
-}
-
-console.log(permutation(["a", "b", "c", "d"]));
-//[["d", "c", "b", "a"], ["c", "d", "b", "a"], ["c", "b", "d", "a"], ["c", "b", "a", "d"], ["d", "b", "c", "a"],
-// ["b", "d", "c", "a"], ["b", "c", "d", "a"], ["b", "c", "a", "d"], ["d", "b", "a", "c"], ["b", "d", "a", "c"],
-// ["b", "a", "d", "c"], ["b", "a", "c", "d"], ["d", "c", "a", "b"], ["c", "d", "a", "b"], ["c", "a", "d", "b"],
-// ["c", "a", "b", "d"], ["d", "a", "c", "b"], ["a", "d", "c", "b"], ["a", "c", "d", "b"], ["a", "c", "b", "d"],
-// ["d", "a", "b", "c"], ["a", "d", "b", "c"], ["a", "b", "d", "c"], ["a", "b", "c", "d"]]
diff --git a/problems/wordSquare.js b/problems/wordSquare.js
deleted file mode 100644
index 9d43dce..0000000
--- a/problems/wordSquare.js
+++ /dev/null
@@ -1,35 +0,0 @@
-const validWordSquare = (words) => {
- if (words == null || words.length === 0) {
- return false;
- }
- if (words.length !== words[0].length) {
- return false;
- }
-
- for (let i = 0; i < words.length; i++) {
- for (let j = 0; j < words[i].length; j++) {
- if (words[i][j] !== words[j][i]) {
- return false;
- }
- }
- }
- return true;
-};
-
-let arr = [
- ["b","a","l","l"],
- ["a","r","e","a"],
- ["r","e","a","d"],
- ["l","a","d","y"]
-];
-
-let arr1 = [
- ["a","b","c","d"],
- ["b","n","r","t"],
- ["c","r","m","y"],
- ["d","t","y","e"]
-];
-
-
-console.log(validWordSquare(arr)); // false
-console.log(validWordSquare(arr1)); // true