From 95bba0b0ea2325055133829f28f8d01981e8ac90 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 01:03:10 +0530 Subject: [PATCH 01/17] update (#1) * Graph Theory * Delete Graphs * Graph * Dijkstra Smallest Path * DijkstraSmallestPath after fixing some errors. * Topological Sort directed graphs * correcting name of file * updating DIRECTORY.md * doublylinkedlist * add-doublylinkedlist * add-doublylinkedlist * change in Directory.md * updating DIRECTORY.md Co-authored-by: Nur69 <60115902+Nur69@users.noreply.github.com> Co-authored-by: Stepfen Shawn Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: hmizz --- DIRECTORY.md | 4 + .../Linked List/DoublyLinkedList.js | 197 ++++++++++++++++++ Sorts/TopologicalSort.js | 59 ++++++ maths/DijkstraSmallestPath.js | 118 +++++++++++ maths/graph.js | 94 +++++++++ 5 files changed, 472 insertions(+) create mode 100644 Data Structures/Linked List/DoublyLinkedList.js create mode 100644 Sorts/TopologicalSort.js create mode 100644 maths/DijkstraSmallestPath.js create mode 100644 maths/graph.js diff --git a/DIRECTORY.md b/DIRECTORY.md index b986905b2..c433585b7 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -22,6 +22,7 @@ * Heap * [MinPriorityQueue](https://github.com/TheAlgorithms/Javascript/blob/master/Data%20Structures/Heap/MinPriorityQueue.js) * Linked List + * [DoublyLinkedList](https://github.com/TheAlgorithms/Javascript/blob/master/Data%20Structures/Linked%20List/DoublyLinkedList.js) * [singlylinklist](https://github.com/TheAlgorithms/Javascript/blob/master/Data%20Structures/Linked%20List/singlylinklist.js) * Queue * [Queue](https://github.com/TheAlgorithms/Javascript/blob/master/Data%20Structures/Queue/Queue.js) @@ -43,8 +44,10 @@ ## maths * [abs](https://github.com/TheAlgorithms/Javascript/blob/master/maths/abs.js) * [average mean](https://github.com/TheAlgorithms/Javascript/blob/master/maths/average_mean.js) + * [DijkstraSmallestPath](https://github.com/TheAlgorithms/Javascript/blob/master/maths/DijkstraSmallestPath.js) * [factorial](https://github.com/TheAlgorithms/Javascript/blob/master/maths/factorial.js) * [find lcm](https://github.com/TheAlgorithms/Javascript/blob/master/maths/find_lcm.js) + * [graph](https://github.com/TheAlgorithms/Javascript/blob/master/maths/graph.js) ## Search * [binarySearch](https://github.com/TheAlgorithms/Javascript/blob/master/Search/binarySearch.js) @@ -68,4 +71,5 @@ * [radixSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/radixSort.js) * [selectionSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/selectionSort.js) * [shellSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/shellSort.js) + * [TopologicalSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/TopologicalSort.js) * [wiggleSort](https://github.com/TheAlgorithms/Javascript/blob/master/Sorts/wiggleSort.js) diff --git a/Data Structures/Linked List/DoublyLinkedList.js b/Data Structures/Linked List/DoublyLinkedList.js new file mode 100644 index 000000000..aca5b7eb7 --- /dev/null +++ b/Data Structures/Linked List/DoublyLinkedList.js @@ -0,0 +1,197 @@ +//Hamza chabchoub contribution for a university project +function doubleLinkedList() { + let Node = function(element) { + this.element = element; + this.next = null; + this.prev = null; + } + + let length = 0; + let head = null; + let tail = null; + + //Add new element + this.append = function(element) { + let node = new Node(element); + + if(!head){ + head = node; + tail = node; + }else{ + node.prev = tail; + tail.next = node; + tail = node; + } + + length++; + } + + + //Add element + this.insert = function(position, element) { + + //Check of out-of-bound values + if(position >= 0 && position <= length){ + let node = new Node(element), + current = head, + previous, + index = 0; + + if(position === 0){ + if(!head){ + head = node; + tail = node; + }else{ + node.next = current; + current.prev = node; + head = node; + } + }else if(position === length){ + current = tail; + current.next = node; + node.prev = current; + tail = node; + }else{ + while(index++ < position){ + previous = current; + current = current.next; + } + + node.next = current; + previous.next = node; + + //New + current.prev = node; + node.prev = previous; + } + + length++; + return true; + }else{ + return false; + } + } + + //Remove element at any position + this.removeAt = function(position){ + //look for out-of-bounds value + if(position > -1 && position < length){ + let current = head, previous, index = 0; + + //Removing first item + if(position === 0){ + head = current.next; + + //if there is only one item, update tail //NEW + if(length === 1){ + tail = null; + }else{ + head.prev = null; + } + }else if(position === length - 1){ + current = tail; + tail = current.prev; + tail.next = null; + }else{ + while(index++ < position){ + previous = current; + current = current.next; + } + + //link previous with current's next - skip it + previous.next = current.next; + current.next.prev = previous; + } + + length--; + return current.element; + }else{ + return null; + } + } + + //Get the indexOf item + this.indexOf = function(elm){ + let current = head, + index = -1; + + //If element found then return its position + while(current){ + if(elm === current.element){ + return ++index; + } + + index++; + current = current.next; + } + + //Else return -1 + return -1; + }; + + //Find the item in the list + this.isPresent = (elm) => { + return this.indexOf(elm) !== -1; + }; + + //Delete an item from the list + this.delete = (elm) => { + return this.removeAt(this.indexOf(elm)); + }; + + //Delete first item from the list + this.deleteHead = function(){ + this.removeAt(0); + } + + //Delete last item from the list + this.deleteTail = function(){ + this.removeAt(length-1); + } + + //Print item of the string + this.toString = function(){ + let current = head, + string = ''; + + while(current){ + string += current.element + (current.next ? '\n' : ''); + current = current.next; + } + + return string; + }; + + //Convert list to array + this.toArray = function(){ + let arr = [], + current = head; + + while(current){ + arr.push(current.element); + current = current.next; + } + + return arr; + }; + + //Check if list is empty + this.isEmpty = function(){ + return length === 0; + }; + + //Get the size of the list + this.size = function(){ + return length; + } + + //Get the head + this.getHead = function() { + return head; + } + + //Get the tail + this.getTail = function() { + return tail; + } + } \ No newline at end of file diff --git a/Sorts/TopologicalSort.js b/Sorts/TopologicalSort.js new file mode 100644 index 000000000..e76bfd666 --- /dev/null +++ b/Sorts/TopologicalSort.js @@ -0,0 +1,59 @@ +function TopologicalSorter() { + var graph = {}, + isVisitedNode, + finishTimeCount, + finishingTimeList, + nextNode; + + this.addOrder = function (nodeA, nodeB) { + nodeA = String(nodeA); + nodeB = String(nodeB); + graph[nodeA] = graph[nodeA] || []; + graph[nodeA].push(nodeB); + } + + this.sortAndGetOrderedItems = function () { + isVisitedNode = Object.create(null); + finishTimeCount = 0; + finishingTimeList = []; + + for (var node in graph) { + if (graph.hasOwnProperty(node) && !isVisitedNode[node]) { + dfsTraverse(node); + } + } + + finishingTimeList.sort(function (item1, item2) { + return item1.finishTime > item2.finishTime ? -1 : 1; + }); + + return finishingTimeList.map(function (value) { return value.node }) + } + + function dfsTraverse(node) { + isVisitedNode[node] = true; + if (graph[node]) { + for (var i = 0; i < graph[node].length; i++) { + nextNode = graph[node][i]; + if (isVisitedNode[nextNode]) continue; + dfsTraverse(nextNode); + } + } + + finishingTimeList.push({ + node: node, + finishTime: ++finishTimeCount + }); + } +} + + +/* TEST */ +var topoSorter = new TopologicalSorter(); +topoSorter.addOrder(5, 2); +topoSorter.addOrder(5, 0); +topoSorter.addOrder(4, 0); +topoSorter.addOrder(4, 1); +topoSorter.addOrder(2, 3); +topoSorter.addOrder(3, 1); +console.log(topoSorter.sortAndGetOrderedItems()); diff --git a/maths/DijkstraSmallestPath.js b/maths/DijkstraSmallestPath.js new file mode 100644 index 000000000..059b59461 --- /dev/null +++ b/maths/DijkstraSmallestPath.js @@ -0,0 +1,118 @@ +// starting at s +function solve(graph, s) { + var solutions = {}; + solutions[s] = []; + solutions[s].dist = 0; + + while(true) { + var p = null; + var neighbor = null; + var dist = Infinity; + + + for(var n in solutions) { + if(!solutions[n]) + continue + var ndist = solutions[n].dist; + var adj = graph[n]; + + for(var a in adj) { + + if(solutions[a]) + continue; + + var d = adj[a] + ndist; + if(d < dist) { + + p = solutions[n]; + neighbor = a; + dist = d; + } + } + } + + //no more solutions + if(dist === Infinity) { + break; + } + + //extend parent's solution path + solutions[neighbor] = p.concat(neighbor); + //extend parent's cost + solutions[neighbor].dist = dist; + } + + return solutions; +} +//create graph +var graph = {}; + +var layout = { + 'R': ['2'], + '2': ['3','4'], + '3': ['4','6','13'], + '4': ['5','8'], + '5': ['7','11'], + '6': ['13','15'], + '7': ['10'], + '8': ['11','13'], + '9': ['14'], + '10': [], + '11': ['12'], + '12': [], + '13': ['14'], + '14': [], + '15': [] +} + +//convert uni-directional to bi-directional graph +// var graph = { +// a: {e:1, b:1, g:3}, +// b: {a:1, c:1}, +// c: {b:1, d:1}, +// d: {c:1, e:1}, +// e: {d:1, a:1}, +// f: {g:1, h:1}, +// g: {a:3, f:1}, +// h: {f:1} +// }; + +for(var id in layout) { + if(!graph[id]) + graph[id] = {}; + layout[id].forEach(function(aid) { + graph[id][aid] = 1; + if(!graph[aid]) + graph[aid] = {}; + graph[aid][id] = 1; + }); +} + +//choose start node +var start = '10'; +//get all solutions +var solutions = solve(graph, start); + +console.log("From '"+start+"' to"); +//display solutions +for(var s in solutions) { + if(!solutions[s]) continue; + console.log(" -> " + s + ": [" + solutions[s].join(", ") + "] (dist:" + solutions[s].dist + ")"); +} + +// From '10' to +// -> 2: [7, 5, 4, 2] (dist:4) +// -> 3: [7, 5, 4, 3] (dist:4) +// -> 4: [7, 5, 4] (dist:3) +// -> 5: [7, 5] (dist:2) +// -> 6: [7, 5, 4, 3, 6] (dist:5) +// -> 7: [7] (dist:1) +// -> 8: [7, 5, 4, 8] (dist:4) +// -> 9: [7, 5, 4, 3, 13, 14, 9] (dist:7) +// -> 10: [] (dist:0) +// -> 11: [7, 5, 11] (dist:3) +// -> 12: [7, 5, 11, 12] (dist:4) +// -> 13: [7, 5, 4, 3, 13] (dist:5) +// -> 14: [7, 5, 4, 3, 13, 14] (dist:6) +// -> 15: [7, 5, 4, 3, 6, 15] (dist:6) +// -> R: [7, 5, 4, 2, R] (dist:5) diff --git a/maths/graph.js b/maths/graph.js new file mode 100644 index 000000000..45f3908aa --- /dev/null +++ b/maths/graph.js @@ -0,0 +1,94 @@ +// create a graph class +class Graph { + // defining vertex array and + // adjacent list + constructor(noOfVertices) + { + this.noOfVertices = noOfVertices; + this.AdjList = new Map(); + } + + // functions to be implemented + + // addVertex(v) + // addEdge(v, w) + // printGraph() + + // bfs(v) + // dfs(v) +} + +// add vertex to the graph +addVertex(v) +{ + // initialize the adjacent list with a + // null array + this.AdjList.set(v, []); +} + +// add edge to the graph +addEdge(v, w) +{ + // get the list for vertex v and put the + // vertex w denoting edge between v and w + this.AdjList.get(v).push(w); + + // Since graph is undirected, + // add an edge from w to v also + this.AdjList.get(w).push(v); +} + + +// Prints the vertex and adjacency list +printGraph() +{ + // get all the vertices + var get_keys = this.AdjList.keys(); + + // iterate over the vertices + for (var i of get_keys) +{ + // great the corresponding adjacency list + // for the vertex + var get_values = this.AdjList.get(i); + var conc = ""; + + // iterate over the adjacency list + // concatenate the values into a string + for (var j of get_values) + conc += j + " "; + + // print the vertex and its adjacency list + console.log(i + " -> " + conc); + } +} + + +// Example +var graph = new Graph(6); +var vertices = [ 'A', 'B', 'C', 'D', 'E', 'F' ]; + +// adding vertices +for (var i = 0; i < vertices.length; i++) { + g.addVertex(vertices[i]); +} + +// adding edges +g.addEdge('A', 'B'); +g.addEdge('A', 'D'); +g.addEdge('A', 'E'); +g.addEdge('B', 'C'); +g.addEdge('D', 'E'); +g.addEdge('E', 'F'); +g.addEdge('E', 'C'); +g.addEdge('C', 'F'); + +// prints all vertex and +// its adjacency list +// A -> B D E +// B -> A C +// C -> B E F +// D -> A E +// E -> A D F C +// F -> E C +g.printGraph(); From ea169a26e0243d0aed9a6aa742158a002a4257a7 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 01:32:29 +0530 Subject: [PATCH 02/17] Contributing guidelines --- CONTRIBUTING.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..5aaf1e1f7 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,75 @@ +# Contributing guidelines + +## Before contributing + +Welcome to [TheAlgorithms/Javascript](https://github.com/TheAlgorithms/Javascript)! Before sending your pull requests, make sure that you **read the whole guidelines**. If you have any doubt on the contributing guide, please feel free to [state it clearly in an issue](https://github.com/TheAlgorithms/Javascript/issues/new) + +## Contributing + +### Contributor + +We are very happy that you consider implementing algorithms and data structure for others! This repository is referenced and used by learners from all over the globe. Being one of our contributors, you agree and confirm that: + +- You did your work - no plagiarism allowed + - Any plagiarized work will not be merged. +- Your work will be distributed under [GNU License](License) once your pull request is merged +- You submitted work fulfils or mostly fulfils our styles and standards + +**New implementation** is welcome! For example, new solutions for a problem, different representations for a graph data structure or algorithm designs with different complexity. + +**Improving comments** and **writing proper tests** are also highly welcome. + +### Contribution + +We appreciate any contribution, from fixing a grammar mistake in a comment to implementing complex algorithms. Please read this section if you are contributing your work. + + +Please help us keep our issue list small by adding fixes: #{$ISSUE_NO} to the commit message of pull requests that resolve open issues. GitHub will use this tag to auto close the issue when the PR is merged. + +#### What is an Algorithm? + +An Algorithm is one or more functions (or classes) that: +* take one or more inputs, +* perform some internal calculations or data manipulations, +* return one or more outputs, +* have minimal side effects. + +Algorithms should be packaged in a way that would make it easy for readers to put them into larger programs. + +Algorithms should: +* have intuitive class and function names that make their purpose clear to readers +* use Javascript naming conventions and intuitive variable names to ease comprehension +* be flexible to take different input values +* have Javascript type hints for their input parameters and return values +* raise Javascript exceptions (ValueError, etc.) on erroneous input values + +Algorithms in this repo should not be how-to examples for existing Javascript packages. Instead, they should perform internal calculations or manipulations to convert input values into different output values. Those calculations or manipulations can use data types, classes, or functions of existing Javascript packages but each algorithm in this repo should add unique value. + +#### Coding Style + +We want your work to be readable by others; therefore, we encourage you to note the following: +- Use camelCase for identifier names (variables and functions) +- Names start with a letter +- follow code indentation + - Always use 2 spaces for indentation of code blocks + ``` + function sumOfArray(arrayOfNumbers) { + let sum = 0; + for (let i = 0; i < arrayOfNumbers.length; i++) { + sum += arrayOfNumbers[i]; + } + return (sum); + } + ``` +- Avoid using global variables and avoid '==' +- use 'let' over 'var' +- Better to use ECMAScript 6 +- Avoid importing external libraries for basic algorithms. Only use those libraries for complicated algorithms. + + + +- Most importantly, + - **Be consistent in the use of these guidelines when submitting.** + - Happy coding! + +Writer [@itsvinayak](https://github.com/itsvinayak), May 2020. From 90e13c0ad913ee34d3b1c1e94ccf21a13e2fe907 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 17:56:44 +0530 Subject: [PATCH 03/17] Update CONTRIBUTING.md --- CONTRIBUTING.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5aaf1e1f7..2cd559c9a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,18 +48,29 @@ Algorithms in this repo should not be how-to examples for existing Javascript pa #### Coding Style We want your work to be readable by others; therefore, we encourage you to note the following: +- Must follow [JavaScript Standard Style](https://standardjs.com/) + - Command to install JavaScript Standard Style + ``` + $ npm install standard --save-dev + ``` + - Usage + ``` + $ standard + ``` + - Use camelCase for identifier names (variables and functions) - Names start with a letter - follow code indentation - Always use 2 spaces for indentation of code blocks ``` - function sumOfArray(arrayOfNumbers) { - let sum = 0; + function sumOfArray (arrayOfNumbers) { + let sum = 0 for (let i = 0; i < arrayOfNumbers.length; i++) { - sum += arrayOfNumbers[i]; + sum += arrayOfNumbers[i] } - return (sum); + return (sum) } + ``` - Avoid using global variables and avoid '==' - use 'let' over 'var' From de980d60f1e108ced1ab342be9359cbbf65a6052 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:04:09 +0530 Subject: [PATCH 04/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2cd559c9a..71fdd3080 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,7 @@ Welcome to [TheAlgorithms/Javascript](https://github.com/TheAlgorithms/Javascrip ### Contributor -We are very happy that you consider implementing algorithms and data structure for others! This repository is referenced and used by learners from all over the globe. Being one of our contributors, you agree and confirm that: +We are very happy that you consider implementing algorithms and data structure for others! This repository is referenced and used by learners from around the globe. Being one of our contributors, you agree and confirm that: - You did your work - no plagiarism allowed - Any plagiarized work will not be merged. From edfb047f0436a59de1642ca46ffed9e5fb8afda6 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:04:20 +0530 Subject: [PATCH 05/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 71fdd3080..c5f963e82 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ Welcome to [TheAlgorithms/Javascript](https://github.com/TheAlgorithms/Javascrip We are very happy that you consider implementing algorithms and data structure for others! This repository is referenced and used by learners from around the globe. Being one of our contributors, you agree and confirm that: -- You did your work - no plagiarism allowed +- You did your work - plagiarism is not allowed. - Any plagiarized work will not be merged. - Your work will be distributed under [GNU License](License) once your pull request is merged - You submitted work fulfils or mostly fulfils our styles and standards From 7dd45f85787c4073cb7b6f052f0758bbd979d250 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:06:58 +0530 Subject: [PATCH 06/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c5f963e82..20bf0a794 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,7 +15,7 @@ We are very happy that you consider implementing algorithms and data structure f - Your work will be distributed under [GNU License](License) once your pull request is merged - You submitted work fulfils or mostly fulfils our styles and standards -**New implementation** is welcome! For example, new solutions for a problem, different representations for a graph data structure or algorithm designs with different complexity. +**New implementation** is welcome! For example, new solutions to a problem, different representations of a graph data structure or algorithm designs with different complexity. **Improving comments** and **writing proper tests** are also highly welcome. From 2bad146a960b138b83a25a47155fbd53d09fb3f4 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:07:10 +0530 Subject: [PATCH 07/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 20bf0a794..10d5e85e8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,7 +21,7 @@ We are very happy that you consider implementing algorithms and data structure f ### Contribution -We appreciate any contribution, from fixing a grammar mistake in a comment to implementing complex algorithms. Please read this section if you are contributing your work. +We appreciate any contribution, from fixing grammar mistakes to implementing complex algorithms. Please read this section if you are contributing your work. Please help us keep our issue list small by adding fixes: #{$ISSUE_NO} to the commit message of pull requests that resolve open issues. GitHub will use this tag to auto close the issue when the PR is merged. From 362cd0083eff0ab2877ddf78e3c601f25efc8ed3 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:07:19 +0530 Subject: [PATCH 08/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 10d5e85e8..b2c83355e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,7 +24,7 @@ We are very happy that you consider implementing algorithms and data structure f We appreciate any contribution, from fixing grammar mistakes to implementing complex algorithms. Please read this section if you are contributing your work. -Please help us keep our issue list small by adding fixes: #{$ISSUE_NO} to the commit message of pull requests that resolve open issues. GitHub will use this tag to auto close the issue when the PR is merged. +If you submit a pull request that resolves an open issue, please help us to keep our issue list small by adding `fixes: #{$ISSUE_NO}` to your commit message. GitHub will use this tag to auto close the issue if your PR is merged. #### What is an Algorithm? From 1fd3a0dc4a480fdd062beb1a1d8d4cc0edb61460 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:07:35 +0530 Subject: [PATCH 09/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b2c83355e..6fc8f7515 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -64,12 +64,12 @@ We want your work to be readable by others; therefore, we encourage you to note - Always use 2 spaces for indentation of code blocks ``` function sumOfArray (arrayOfNumbers) { - let sum = 0 - for (let i = 0; i < arrayOfNumbers.length; i++) { - sum += arrayOfNumbers[i] - } - return (sum) - } + let sum = 0 + for (let i = 0; i < arrayOfNumbers.length; i++) { + sum += arrayOfNumbers[i] + } + return (sum) + } ``` - Avoid using global variables and avoid '==' From abb90661a52bd2efafb5b615a47bc53727f38954 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:07:47 +0530 Subject: [PATCH 10/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6fc8f7515..51c84074b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,7 +38,7 @@ Algorithms should be packaged in a way that would make it easy for readers to pu Algorithms should: * have intuitive class and function names that make their purpose clear to readers -* use Javascript naming conventions and intuitive variable names to ease comprehension +* use JavaScript naming conventions and intuitive variable names to ease comprehension * be flexible to take different input values * have Javascript type hints for their input parameters and return values * raise Javascript exceptions (ValueError, etc.) on erroneous input values From f8a78b3b686f7d84fbcaf1f9c1ae126ba67ac305 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:07:57 +0530 Subject: [PATCH 11/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 51c84074b..606f2351b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,7 +40,6 @@ Algorithms should: * have intuitive class and function names that make their purpose clear to readers * use JavaScript naming conventions and intuitive variable names to ease comprehension * be flexible to take different input values -* have Javascript type hints for their input parameters and return values * raise Javascript exceptions (ValueError, etc.) on erroneous input values Algorithms in this repo should not be how-to examples for existing Javascript packages. Instead, they should perform internal calculations or manipulations to convert input values into different output values. Those calculations or manipulations can use data types, classes, or functions of existing Javascript packages but each algorithm in this repo should add unique value. From b74391bbe899dbad346c6a727f91034ac92812c3 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:08:12 +0530 Subject: [PATCH 12/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 606f2351b..b9ece7198 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,7 +40,7 @@ Algorithms should: * have intuitive class and function names that make their purpose clear to readers * use JavaScript naming conventions and intuitive variable names to ease comprehension * be flexible to take different input values -* raise Javascript exceptions (ValueError, etc.) on erroneous input values +* raise JavaScript exceptions (RangeError, etc.) on erroneous input values Algorithms in this repo should not be how-to examples for existing Javascript packages. Instead, they should perform internal calculations or manipulations to convert input values into different output values. Those calculations or manipulations can use data types, classes, or functions of existing Javascript packages but each algorithm in this repo should add unique value. From e3e4d9706647c12b958157c8bd0267acd27e9cb1 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:08:22 +0530 Subject: [PATCH 13/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b9ece7198..9b3d62875 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,7 +42,7 @@ Algorithms should: * be flexible to take different input values * raise JavaScript exceptions (RangeError, etc.) on erroneous input values -Algorithms in this repo should not be how-to examples for existing Javascript packages. Instead, they should perform internal calculations or manipulations to convert input values into different output values. Those calculations or manipulations can use data types, classes, or functions of existing Javascript packages but each algorithm in this repo should add unique value. +Algorithms in this repo should not be how-to examples for existing JavaScript packages. Instead, they should perform internal calculations or manipulations to convert input values into different output values. Those calculations or manipulations can use data types, classes, or functions of existing JavaScript packages but each algorithm in this repo should add unique value. #### Coding Style From 31cd69ea84c5d42db86ab9249a79537508dbb7c8 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:08:32 +0530 Subject: [PATCH 14/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b3d62875..71a083c4c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,16 +46,15 @@ Algorithms in this repo should not be how-to examples for existing JavaScript pa #### Coding Style -We want your work to be readable by others; therefore, we encourage you to note the following: -- Must follow [JavaScript Standard Style](https://standardjs.com/) +To maximize the readability and correctness of our code, we require that new submissions follow [JavaScript Standard Style](https://standardjs.com/) - Command to install JavaScript Standard Style ``` - $ npm install standard --save-dev - ``` + $ npm install standard --save-dev + ``` - Usage ``` - $ standard - ``` + $ standard MyFile.js // if that fails, try: npx standard MyFile.js + ``` - Use camelCase for identifier names (variables and functions) - Names start with a letter From 5c1b4e79ae4e6d68980a004e2a28bada7c22a52e Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:08:41 +0530 Subject: [PATCH 15/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 71a083c4c..4819169cb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -71,7 +71,7 @@ To maximize the readability and correctness of our code, we require that new sub ``` - Avoid using global variables and avoid '==' -- use 'let' over 'var' +- Please use 'let' over 'var' - Better to use ECMAScript 6 - Avoid importing external libraries for basic algorithms. Only use those libraries for complicated algorithms. From 5267cbaa6a300a9a8b286815ace00a5c90b52417 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:08:51 +0530 Subject: [PATCH 16/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4819169cb..c21d9a853 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,7 +56,7 @@ To maximize the readability and correctness of our code, we require that new sub $ standard MyFile.js // if that fails, try: npx standard MyFile.js ``` -- Use camelCase for identifier names (variables and functions) +- Use camelCase for with leading character lowercase for identifier names (variables and functions) - Names start with a letter - follow code indentation - Always use 2 spaces for indentation of code blocks From 8c2aa0f2964c167713ee506c63aad4663edc1f63 Mon Sep 17 00:00:00 2001 From: vinayak Date: Sun, 3 May 2020 20:09:00 +0530 Subject: [PATCH 17/17] Update CONTRIBUTING.md Co-authored-by: Christian Clauss --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c21d9a853..ee76d9b75 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -72,7 +72,7 @@ To maximize the readability and correctness of our code, we require that new sub ``` - Avoid using global variables and avoid '==' - Please use 'let' over 'var' -- Better to use ECMAScript 6 +- We strongly recommend the use of ECMAScript 6 - Avoid importing external libraries for basic algorithms. Only use those libraries for complicated algorithms.