Complete "longest common ..." examples (#100)

* no else return

* fix var ref

* fix importing/requiring dependencies

* complete longest common examples
This commit is contained in:
Max Beatty
2019-03-28 14:52:55 -07:00
committed by Aditya Bhargava
parent c23ca90b83
commit 5b675cc2e8
22 changed files with 235 additions and 125 deletions

View File

@@ -3,16 +3,12 @@
* @param {Array} arr Array of numbers
* @return {number} Sum of the numbers
*/
const sumLoop = ( arr ) => {
let result = 0;
for ( let i = 0; i < newArr.length; i++ ) {
result += newArr[i];
}
return result;
const sumLoop = arr => {
let result = 0;
for (let i = 0; i < arr.length; i++) {
result += arr[i];
}
return result;
};
let arr = [1, 2, 3, 4];
console.log( sumLoop( arr ) ); // 10
console.log(sumLoop([1, 2, 3, 4])); // 10

View File

@@ -3,14 +3,6 @@
* @param {Array} arr Array of numbers
* @return {number} Sum of the numbers
*/
const sumReduce = ( arr ) => {
let result = newArr.reduce( ( curr, prev ) => {
return curr + prev;
} );
const sumReduce = arr => arr.reduce((curr, prev) => curr + prev);
return result;
};
let arr = [1, 2, 3, 4];
console.log( sumReduce( arr ) ); // 10
console.log(sumReduce([1, 2, 3, 4])); // 10