Skip to content

Instantly share code, notes, and snippets.

View prajapati-parth's full-sized avatar
:octocat:
undefined

Parth Prajapati prajapati-parth

:octocat:
undefined
View GitHub Profile
@prajapati-parth
prajapati-parth / array-chunker.js
Created February 4, 2018 10:14
Function to separate an array into an array with smaller chunks
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 September 26, 2017 11:05
A simple for loop with caching
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
}
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}>