• js数组去重、获取重复数据以及获取非重复数据--一句话函数


    数组去重

    let arr = [11, 23, 26, 23, 11, 9]
    const deduplication = arr => [...new Set(arr)]
    
    console.log(deduplication(arr));  // [ 11, 23, 26, 9 ]
    

    保留数组中非重复数据

    let arr = [11, 23, 26, 23, 11, 9]
    const filterNonUnique = arr => arr.filter(i => arr.indexOf(i) === arr.lastIndexOf(i))
    
    console.log(filterNonUnique(arr));  // [ 26, 9 ]
     
    

    保留数组中重复元素

    let arr = [11, 23, 26, 23, 11, 9]
    const filterUnique = arr => arr.filter(i => arr.indexOf(i) !== arr.lastIndexOf(i))
    
    console.log(filterUnique(arr)); // [ 11, 23, 23, 11 ]
     
    

    原文:https://blog.csdn.net/momDIY/article/details/81351140 

  • 相关阅读:
    hdu 5072 Coprime (容斥)
    洛谷 P1411 树 (树形dp)
    Tr/ee AtCoder
    sys.path
    uname
    sys.platform
    Eclipse Basic
    Eclipse Color Theme
    Pydev
    scons
  • 原文地址:https://www.cnblogs.com/yjgbk/p/10837993.html
Copyright © 2020-2023  润新知