Skip to content

Instantly share code, notes, and snippets.

View guangLess's full-sized avatar

Guang guangLess

View GitHub Profile
const todo = (state, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
completed:false,
text: action.text,
};
case 'TOGGLE_TODO':
if(state.id !== action.id){
let list = [2,3,1];
const addCounter = (list)=>{
return[...list, 0];
}
const removeCounter = (list, index) => {
return [
...list.slice(0,index),
...list.slice(index+1)
const counter = (state = 0, action) => {
switch (action.type){
case 'INCREMENT' :
return state + 1;
case 'DECREMENT' :
return state -1;
default:
return state;
}
}
import React from 'react';
import Footer from './Footer.js';
import Sidebar from './Sidebar.js';
import AllAlbums from './AllAlbums.js';
import SingleAlbum from './SingleAlbum.js'
import axios from 'axios';
export default class Main extends React.Component {
constructor(props) {
super(props);
@guangLess
guangLess / swift.optional.map.interviewFollowUp
Created June 20, 2016 18:57
different ways to unwrap optional
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! LineTableViewCell
let eachLine = subwayDataStore.subwayArrayList[indexPath.row]
Optional option 1 :
if let iconName = eachLine.letter {
cell.iconLabel.image = UIImage(named:iconName.lowercaseString)
}
Optional option 2 :
let imageName = eachLine.letter.map {_ in
eachLine.letter!.lowercaseString
@guangLess
guangLess / Array Question FlatironSchool-interview-Question
Last active December 19, 2015 16:55
Array Question FlatironSchool-interview-Question
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *germanMakes = @[@"A"];
NSArray * fin = [self sortMidtoFront:germanMakes];
NSLog(@"fin = [%@]",fin);
NSLog(@"testing Number is %lu",(unsigned long)[self checkMidNumber:2]);