import React from 'react';
import ReactDOM from 'react-dom';
class Toggle extends React.Component {
constructor(props) {
super(props);
this.state= {
- The
filter()
method creates a new array with array elements that passes a test. - The
filter()
method takes a callback function which has 3 arguments:- The item value
- The item index
- The array itself
In this example I am you looking to simply remove all objects(items in the array) for which a category has already appeared once. You can do this with the Vanilla Javascript filter method. You simply have to use an object to keep count of whether the object has appeared before or not.
TThe sort()
method sorts the items of an array.
The sort order can be either alphabetic or numeric, and either ascending (up) or descending (down).
By default, the sort()
method sorts the values as strings in alphabetical and ascending order.
This works well for strings ("Apple" comes before "Banana")
. However, if numbers are sorted as strings, "25" is bigger than "100", because "2" is bigger than "1".
The concat
method is used to join two or more arrays.
This method does not change the existing arrays, but returns a new array, containing the values of the joined arrays.
// join two arrays
var hege = ["Cecilie", "Lone"];
var stale = ["Emil", "Tobias", "Linus"];
var children = hege.concat(stale);
In JavaScript, the constructor
property returns the constructor function for an object.
The return value is a reference to the function, not the name of the function:
For JavaScript arrays the constructor property returns function Array() { [native code] }
For JavaScript numbers the constructor property returns function Number() { [native code] }
The reduce()
method reduces the array to a single value.
The reduce()
method executes a provided function for each value of the array (from left-to-right).
The return value of the function is stored in an accumulator (result/total).
Note: reduce()
does not execute the function for array elements without values.
- Create a
.bash_profile
in your~/
home directory on your mac or linux machine. - Copy the following snippet of code into your
.bash_profile
.
# Sexy Bash Prompt, inspired by "Extravagant Zsh Prompt"
# Screenshot: http://img.gf3.ca/d54942f474256ec26a49893681c49b5a.png
# A big thanks to \amethyst on Freenode