We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
var arr = [ { name: '小米1', value: 1, type: 2, date: '2017-06-07T08:00:01.589Z' }, { name: '锤子T1', value: 1, type: 2, date: '2017-06-07T08:10:01.589Z' }, { name: '小米2', value: 1, type: 4, date: '2017-06-07T08:00:01.589Z' }, { name: '小米2', value: 4, type: 4, date: '2017-06-07T08:10:21.189Z' }, { name: '小米4', value: 1, type: 4, date: '2017-06-07T08:00:01.560Z' }, { name: '小米4', value: 2, type: 4, date: '2017-06-07T08:10:31.584Z' }, { name: '小米6', value: 1, type: 3, date: '2017-06-07T08:00:01.589Z' }, { name: '小米5s', value: 1, type: 4, date: '2017-06-07T08:00:01.589Z' }, { name: '锤子T2', value: 1, type: 4, date: '2017-06-07T08:00:01.589Z' }, { name: '锤子T1', value: 4, type: 4, date: '2017-06-07T08:06:01.589Z' }, { name: '魅蓝note5', value: 1, type: 4, date: '2017-06-07T08:00:01.589Z' }, { name: '魅蓝note2', value: 5, type: 4, date: '2017-06-02T08:07:01.589Z' }, { name: '魅蓝note2', value: 6, type: 4, date: '2017-06-07T08:00:01.589Z' }, { name: '魅蓝note3', value: 1, type: 4, date: '2017-06-05T08:00:01.589Z' }, { name: '魅蓝note', value: 1, type: 4, date: '2017-06-07T08:00:01.589Z' }, { name: 'oppor9', value: 7, type: 4, date: '2017-06-04T08:04:01.588Z' }, { name: '华为p9', value: 1, type: 4, date: '2017-06-02T08:00:01.577Z' }, { name: '华为p9', value: 2, type: 4, date: '2017-06-07T08:00:01.110Z' }, { name: '华为p10', value: 1, type: 1, date: '2017-06-07T08:00:01.534Z' } ]; /** * type为4的数据过滤出来, * 按相同的 name + date(按天)合并value(value累加), * 最后按 value 降序(从大到小)排序. * 然后每行按照 "小米2,4,2017年06月07日" 的格式, 打印出来. */ var filterArr = arr.filter((item) => { return item.type === 4 }) var concatArr = filterArr.reduce((last, current) => { const saveItem = last.find((item) => { return item.name === current.name && item.date.slice(10) === current.date.slice(10) }) if (saveItem) { saveItem.value += current.value } else { last.push(current) } return last }, []) var sortArr = concatArr.sort((a, b) => b.value - a.value) var log = sortArr.forEach((item) => { var date = new Date(item.date) var formatDate = `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日` console.log(`${item.name},${item.value}, ${formatDate}`) }) function hexToRgb(hex) { // 将16进制转为RGB形式 var reg = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]){6}$/ var rgb = [] if (reg.test(hex)) { var newHex = hex.replace('#', '') var resArr = [].slice.call(newHex) var arr = [] if (resArr.length === 6) { arr = [resArr[0] + resArr[1], resArr[2] + resArr[3], resArr[4] + resArr[5]] } else { arr = [resArr[0].repeat(2), resArr[1].repeat(2), resArr[2].repeat(2)] } for (var i=0; i<arr.length; i++) { rgb.push(parseInt(arr[i], 16)) } } else { console.log('请输入正确的16进制色值') } return rgb.join() } hexToRgb('#2b5d2f')
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: