Skip to content

Instantly share code, notes, and snippets.

View ramsunvtech's full-sized avatar
💭
Full Stack Developer (Java, React, React Native)

Venkat.R ramsunvtech

💭
Full Stack Developer (Java, React, React Native)
View GitHub Profile
@ramsunvtech
ramsunvtech / sumOfArray.js
Created September 25, 2018 19:42
Sum of Three Arrays
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));
@ramsunvtech
ramsunvtech / flatMultiDimensionalArray.js
Created September 25, 2018 18:35
Flatten the Multi-dimensional Array
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;
}
@ramsunvtech
ramsunvtech / thisAndArgumentsInFunctions.js
Created September 25, 2018 15:33
This and Arguments in Functions
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
@ramsunvtech
ramsunvtech / recursiveAddFunctionCurrying.js
Last active September 25, 2018 15:19
Recursive Add Function Currying
function add (a) {
return function (b) {
if(!b) {
return a;
}
return add(a + b);
}
}
add(1)(2)(3)(4)(5)() // 15
@ramsunvtech
ramsunvtech / simpleAddFunctionCurry.js
Created September 25, 2018 15:10
Simple Add Function Currying
function add (a) {
return function (b) {
return a + b;
}
}
add(1)(2) // 3
@ramsunvtech
ramsunvtech / groupBy.js
Created September 25, 2018 15:07
Group By - ES6
function groupBy(list, props) {
return list.reduce((a, b) => {
(a[b[props]] = a[b[props]] || []).push(b);
return a;
}, {});
}
// Usage.
groupBy([{
id: 1,
@ramsunvtech
ramsunvtech / const-syntax-errors.js
Created August 8, 2018 19:05
Various Syntax Error for const variables on Typo mistakes
/*
* 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
@ramsunvtech
ramsunvtech / let-syntax-errors.js
Created August 8, 2018 19:05
Various Syntax Error for let variables on Typo mistakes
/*
* 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
@ramsunvtech
ramsunvtech / var-syntax-errors.js
Created August 8, 2018 19:04
Various Syntax Error for var variables on Typo mistakes
/*
* 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
@ramsunvtech
ramsunvtech / async-parallel-unit-testing.js
Created February 2, 2018 10:06
Async Parallel Unit Testing
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'];