This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = [1,2,3,1,1]; | |
var b = [4,5,6,1]; | |
var c = [1,1,1]; | |
function sumArray(a,b,c) { | |
const max = Math.max(a.length, b.length, c.length); | |
const sumList = []; | |
for(let i = 0; i < max; i++) { | |
sumList.push((a[i] || 0) + (b[i] || 0) + (c[i] || 0)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flat([[1, 2], 3, [4], [5, 6]]); // [1, 2, 3, 4, 5, 6] | |
// Without .reduce() Function | |
function flat(list) { | |
const flatList = []; | |
list.forEach((item) => { | |
if (Array.isArray(item)) { | |
flatList.push(...item); | |
return; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function simpleFunction() { | |
console.log(this); // window Object. | |
console.log(arguments); // 1, 2, 3 | |
} | |
simpleFunction(1, 2, 3); | |
const arrowFunction = () => { | |
console.log(this); // window Object. | |
console.log(arguments); // Reference Error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add (a) { | |
return function (b) { | |
if(!b) { | |
return a; | |
} | |
return add(a + b); | |
} | |
} | |
add(1)(2)(3)(4)(5)() // 15 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add (a) { | |
return function (b) { | |
return a + b; | |
} | |
} | |
add(1)(2) // 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function groupBy(list, props) { | |
return list.reduce((a, b) => { | |
(a[b[props]] = a[b[props]] || []).push(b); | |
return a; | |
}, {}); | |
} | |
// Usage. | |
groupBy([{ | |
id: 1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Below are the possible syntax errors with all stupid typo mistakes for const variables. | |
* Tested in Chrome, Firefox, Safari and IE Edge. | |
* Venkat.R | |
*/ | |
// const a= | |
// Chrome - SyntaxError: Unexpected end of input | |
// Firefox - SyntaxError: expected expression, got end of script | |
// Safari - SyntaxError: Unexpected EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Below are the possible syntax errors with all stupid typo mistakes for let variables. | |
* Tested in Chrome, Firefox, Safari and IE Edge. | |
* Venkat.R | |
*/ | |
// let a= | |
// Chrome - SyntaxError: Unexpected end of input | |
// Firefox - SyntaxError: expected expression, got end of script | |
// Safari - SyntaxError: Expected an identifier but found 'a' instead |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Below are the possible syntax errors with all stupid typo mistakes for var variables. | |
* Tested in Chrome, Firefox, Safari and IE Edge. | |
* Venkat.R | |
*/ | |
// var a= | |
// Chrome - SyntaxError: Unexpected end of input | |
// Firefox - SyntaxError: expected expression, got end of script | |
// Safari - SyntaxError: Unexpected EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mocha = require('mocha'); | |
const expect = require('chai').expect; | |
const sinon = require('sinon'); | |
const db = require('./db'); | |
const asyncFile = require('./parallel'); | |
describe('Async Parallel.js', () => { | |
let params, resultValues, userDataStub, activityDataStub, activityDataSpy; | |
before(() => { | |
params = ['first arg', 'second arg']; | |
resultValues = ['First Result', 'Second Result']; |