Added more implementations (JS) (#67)

* Added recursive binary search (JS)

* Added recursive selection sorting

* Added another loop implementation sum func by reduce (JS)

* Recursion reduced by one iteration

* Recursive binary search in ES6 added to appropriate folder

* JS files ordered by standards (ES4/ES6)

* Added hashtable implementation in JS

* Fixed typo with LENGTH prop

* Added Euclidian algorithm for two numbers and set of them

* Added universal selection sort

* Commented output

* Added ES6 version of Euclidean algorithm

* Converted from ES6 to ES5

* #69 Added search for LCS

* #69 added levenstein algorithm

* Removed excessive property

* Removed excessive file

* Removed excessive function calls

* Removed excessive file

* Removed excessive file

* Renamed

* Fixed indentation
This commit is contained in:
Artem Solovev
2018-08-24 21:21:54 +03:00
committed by Aditya Bhargava
parent a5fe9178dd
commit 0d5d0164ce
12 changed files with 502 additions and 29 deletions

View File

@@ -1,11 +1,18 @@
'use strict';
/**
* Sums values in array by loop "for"
* @param {Array} arr Array of numbers
* @return {number} Sum of the numbers
*/
function sumLoop( arr ) {
var result = 0;
function sum(arr) {
let total = 0;
for (let x = 0; x < arr.length; x++) {
total += arr[x];
}
return total;
for ( var i = 0; i < newArr.length; i++ ) {
result += newArr[i];
}
return result;
}
console.log(sum([1, 2, 3, 4])) // 10
var arr = [1, 2, 3, 4];
console.log( sumLoop( arr ) ); // 10

View File

@@ -0,0 +1,16 @@
/**
* Sums values in array by function "reduce"
* @param {Array} arr Array of numbers
* @return {number} Sum of the numbers
*/
function sumReduce( arr ) {
var result = newArr.reduce( ( curr, prev ) => {
return curr + prev;
} );
return result;
}
var arr = [1, 2, 3, 4];
console.log( sumReduce( arr ) ); // 10

View File

@@ -1,10 +1,13 @@
'use strict';
const arr = [1, 2, 3, 4];
function sum(list) {
if (list.length === 0) {
return 0;
}
return list[0] + sum(list.slice(1));
}
/**
* Sums values in array recursively
* @param {Array} arr Array of numbers
* @return {number} Sum of the numbers
*/
const sumRecursive = ( arr ) => {
if ( arr.length == 1 ) return arr[0];
return arr[0] + sumRecursive( arr.slice( 1 ) );
};
console.log(sum([1, 2, 3, 4])) // 10
console.log( sumRecursive( arr ) ); // 10