Skip to content

Instantly share code, notes, and snippets.

View veeracs's full-sized avatar

Chandra Veera veeracs

View GitHub Profile
@veeracs
veeracs / matching-pairs.js
Last active January 7, 2020 14:38
Return the total number of matching pairs of numbers
function numberPairs(n, ar) {
if (n !== ar.length) {
console.error('Invalid array length');
}
const obj = {};
const pairs = [];
const pairsLength = 0;
do {
@veeracs
veeracs / flatten-arrays.js
Created December 15, 2018 13:46
Flatten Arrays using Reducer
const myarr = [1,2,[3]];
function flatten(arr) {
if (Array.isArray(arr)) {
return arr.reduce((prev, next) => {
return prev.concat(flatten(next));
}, []);
} else {
return arr;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
</script>
@veeracs
veeracs / ellipsis.js
Last active September 28, 2016 22:31
Ellipsis
(function ellipsis(str, charLimit) {
var result = [];
var letters = 0;
str.split(' ').forEach(function(word, index) {
if (letters < charLimit) {result.push(word)}
letters += word.length;
});
console.log(result.join(' ') + ' ...');
})("Hero congressman calls out conservatives on racist abortion restrictions", 40);
@veeracs
veeracs / reducers.js
Created July 26, 2016 22:00 — forked from gaearon/reducers.js
How I'd do code splitting in Redux (pseudo code, not tested!)
import { combineReducers } from 'redux';
import users from './reducers/users';
import posts from './reducers/posts';
export default function createReducer(asyncReducers) {
return combineReducers({
users,
posts,
...asyncReducers
});
@veeracs
veeracs / functional-component.js
Created April 6, 2016 19:18
An example functional component in React
/**
* External dependencies
*/
import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import classNames from 'classnames';
/**
@veeracs
veeracs / introrx.md
Created March 2, 2016 20:00 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@veeracs
veeracs / .scss-lint.yml
Created February 26, 2016 14:40 — forked from meleyal/.scss-lint.yml
scss-lint `PropertySortOrder` config based on @mdo's Code Guide / recess
# based on http://git.io/hpl2Gw
linters:
PropertySortOrder:
order:
- position
- top
- right
- bottom
- left