Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARTS 第九周(2019.11.11-2019.11.17) #9

Open
caimel opened this issue Nov 29, 2019 · 0 comments
Open

ARTS 第九周(2019.11.11-2019.11.17) #9

caimel opened this issue Nov 29, 2019 · 0 comments

Comments

@caimel
Copy link
Owner

caimel commented Nov 29, 2019

Algorithm 两个数组的交集

  • 题目: 两个数组的交集
  • 思路:
    遍历数组一,将数组一中的每一项看数组二中是否存在,如果存在则加到新的数组中,
    并且数足而将对应的项删掉,避免出现的次数不一致
/**
 * @param {number[]} nums1
 * @param {number[]} nums2
 * @return {number[]}
 */
var intersect = function(nums1, nums2) {
    let result = [];
    for (let i = 0; i < nums1.length; i++) {
        var index = nums2.indexOf(nums1[i]);
        if (index !== -1) {
            result.push(nums1[i]);
            nums2.splice(index, 1)
        }
    }
    return result;

};
  • 结果:61 / 61 个通过测试用例
    执行用时:68 ms

Review Vue.js 高级响应式 API 以及带缓存的 Getter 的使用

https://engineroom.teamwork.com/vue-js-advanced-reactivity-api-and-caching-method-style-getters-a80979b6660

Tip 使用react-native-picker封装时间选择器组件

https://github.com/beefe/react-native-picker

  • 实践
/*
 * 先安装 npm install  react-native-picker  
 * 然后 链接 react-native link react-native-picker
 * callBack    选择后的回调方法 返回值
 * 
 * */
import React, { Component } from 'react';
import { StyleSheet, Text, TouchableHighlight } from 'react-native';
import { scaleFontSize, scaleSize, scaleLandScapeSize } from '../utils/screen'
import Picker from 'react-native-picker';
let _Picker = Picker;
class TimePicker extends Component {
	constructor(props) {
		super(props);
		this.state = {
			data: []
		};
	}
	//组件渲染前
	componentWillMount() {
	}
	//组件渲染后
	componentDidMount() {
	}
	//组件销毁
	componentWillUnmount() {
		_Picker.hide();
	}
	//时间
	time = () => {
		let date = new Date();
		let h = date.getHours();
		let m = date.getMinutes();
		let data = [
			[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
			[]
		]
		for (let i = 0; i < 60; i++) {
			data[1].push(i);
		}
		this.pickerInit(data, [h, m], _('时间选择'));
	}
	
	//显示Picker组件
	onPresss = () => {
		this.time();
	}
	render() {
		return (
			<TouchableHighlight
				underlayColor="#f1f1f1"
				style={styles.picker}
				onPress={this.onPresss}
			>
				<Text style={styles.txt}>
					{this.props.title}
				</Text>
			</TouchableHighlight>
		);
	}
	//组件初始化
	pickerInit = (data, selectedValue, title) => {
		Picker.init({
			pickerData: data,
			selectedValue: selectedValue,
			pickerTitleText: title,
			pickerConfirmBtnText: _('确定'),
			pickerCancelBtnText: _('取消'),
			//确定
			onPickerConfirm: data =>data = data.join(':');
				this.props.callBack(data);
			},
		});
		_Picker.show();
	}
}
const styles = StyleSheet.create({
	picker: {
		width:scaleSize(110),
	},
	txt: {
		fontSize: scaleFontSize(8),
		textAlign:'center',
		padding: scaleSize(6),
		borderWidth: scaleSize(1),
		borderColor: '#ccc',
		color: 'black'
	}
}); 

export default (TimePicker)

Share Immutable 详解及 React 中实践

camsong/blog#3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant