alternate
v1.0.2
Published
Alternate between two or more values
Downloads
309
Readme
alternate
Install
npm install --save alternate
Usage
Example 1
const alternate = require('alternate');
const a = new alternate(true, false);
// .next()
a.next() // returns true
a.next() // returns false
a.next() // returns true
a.next() // returns false
// .peek()
a.peek() // returns true
a.peek() // returns true
a.next() // returns true
a.peek() // returns false
a.peek() // returns false
Example 2
const alternate = require('alternate');
const a = new alternate('one', 'two', 3, 4);
a.next() // returns 'one'
a.next() // returns 'two'
a.next() // returns 3
a.next() // returns 4
a.next() // returns 'one'
Usage with React
import React from 'react';
import Alternate from 'alternate';
const rows = ['row1', 'row2', 'row3', 'row4'];
const Table = () => {
const alternateRowColor = new Alternate('red', 'yellow');
return (
<div>
{rows.map(row => (
<div style={{ backgroundColor: alternateRowColor.next() }}>
{row}
</div>
))}
</div>
);
};
export default Table;