Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
undefined

Parth Prajapati prajapati-parth

:octocat:
undefined
View GitHub Profile
@prajapati-parth
prajapati-parth / array-chunker.js
Created Feb 4, 2018
Function to separate an array into an array with smaller chunks
View array-chunker.js
chunkArray(arr, size) {
let arrLength = arr.length,
mainLength = Math.ceil(arrLength/size),
mainArray = [],
chunkArray = []
for(var i=1; i<=arrLength; i++) {
if (i % size === 1) {
// starting new chunk -> clear chunk array and push
chunkArray = []
@prajapati-parth
prajapati-parth / cached-for-loop.js
Created Sep 26, 2017
A simple for loop with caching
View cached-for-loop.js
let items = [
//unknown number of items
]
// normal for loop
// here items.length is calculated each time the loop cycles
for (let i=0; i<items.length; i++) {
// inside for
}
View tr-class-function-table.jsx
function rowClassNameFormat(row, rowIdx) {
// row is whole row object
// rowIdx is index of row
return rowIdx % 2 === 0 ? 'td-column-function-even-example' : 'td-column-function-odd-example';
}
class TrClassStringTable extends React.Component {
render() {
return (
<BootstrapTable data={ products } trClassName={this.rowClassNameFormat}>