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.04-2019.11.10) #8

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

ARTS 第八周(2019.11.04-2019.11.10) #8

caimel opened this issue Nov 22, 2019 · 0 comments

Comments

@caimel
Copy link
Owner

caimel commented Nov 22, 2019

Algorithm 移动零

  • 题目:移动零
  • 思路:
    将为零的值移动到数组末尾,反之就是将非零的值移动到数组前面
    为了减少移动次数,从数组的头部开始遍历,并使用变量nozeroIndex 记录非零值的下标,每遇到非零就按顺序填充数组,最后补0
/**
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var moveZeroes = function(nums) {
   let nozeroIndex = 0
   for(let i = 0; i < nums.length;i++){
       if(nums[i] !== 0){
           nums[nozeroIndex++] = nums[i]
       }
   }
    while(nozeroIndex < nums.length){
        nums[nozeroIndex++] = 0
    }
    return nums
    
};
  • 结果:21 / 21 个通过测试用例
    执行用时:84 ms

Review vuejs的最佳实践

https://blog.usejournal.com/vue-js-best-practices-c5da8d7af48d

复述:

本文列出了14个点,描述了vuejs开发中需要注意的细节,包括变量命名规则,组件命名规则,事件必须又返回等,还列出了这些实践对应的好处。如:使用$ on监听事件时,记住使用destroy()上的$ off删除该监听器。 这可以防止发生内存泄漏。

Tip 使用git合并分支

例子:将main分支合并到branch

  • 方法一:
    1.首先切换到branch分支上
    2.git checkout branch // 确认本地与分支branch一致
    3.git merge main // 将main分支合并过来
    4.这个时候按情况解决冲突
    5.git status //查看当前状态
    6.git commit -m '提交的备注信息' // 提交代码
  1. git push origin branch //将本地代码推送
  • 方法二:使用工具TortoiseGitz进行合并
    1.在项目目录下点击右键->切换->【选择分支branch】
    2.拉取代码
    3.点击右键->合并->【选择分支main】
    4.解决冲突
    5.提交代码
    6.推送

Share 使用SheetJS+react-native-fs实现数据导出成excel文件

https://github.com/SheetJS/sheetjs/tree/7e932aec0080256b15a824a71e65a6755a9d386c/demos/react
实践:

import RNFS from 'react-native-fs'
import XLSX from 'xlsx'
 //将数据格式化成XLSX
 let exportsData = [
    [ "id",    "name", "value" ],
    [    1, "sheetjs",    7262 ],
    [    2, "js-xlsx",    6969 ]
  ]
    let rnfsPath =
      Platform.OS === 'ios'
        ? RNFS.LibraryDirectoryPath
        : RNFS.ExternalDirectoryPath
    let path = ''
    try {
      // 打包时要修改路径
      path = updateTool.getSdPath() + '/voerkabeeHistoryMessages.xlsx'
      // 测试路径
      // path = '/mnt/shared/geny_share/voerkabeeHistoryMessages.xlsx'
    } catch (e) {
      logger.error('get local info path fail ' + e)
    }
    const workBook = XLSX.utils.book_new()
    const workSheet = XLSX.utils.aoa_to_sheet(exportsData)
    XLSX.utils.book_append_sheet(workBook, workSheet, "SheetJS");
    const wbout = XLSX.write(workBook, { type: 'buffer', bookType: "xlsx" });
    // 写文件至path
    RNFS.writeFile(path, wbout, 'ascii')
      .then(success => {
        logger.debug('save data to local success')
        _this.setState({
          isLoading: false,
          downLoadVisible: true,
          downLoadInfo: _('导出成功')
        })
      })
      .catch(err => {
        logger.error('save data to local fail ' + err)
        _this.setState({
          isLoading: false,
          downLoadVisible: true,
          downLoadInfo: _('导出失败')
        })
      })

  }
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