摘要: 241.返回数组中第 n 个元素(支持负数) 方案一:slice function nthElement(arr, n = 0) { return (n >= 0 ? arr.slice(n, n + 1) : arr.slice(n))[0]; } nthElement([1,2,3,4,5], 阅读全文
posted @ 2021-04-09 13:34 czfeng 阅读(102) 评论(1) 推荐(0) 编辑
摘要: 11.判断是否为数字 /** * @description 判断是否为数字 * @param value * @returns {boolean} */ export function isNumber(value) { const reg = /^[0-9]*$/; return reg.test 阅读全文
posted @ 2021-04-09 12:01 czfeng 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 181.如何在等待指定时间后调用提供的函数? const delay = (fn, wait, ...args) => setTimeout(fn, wait, ...args); delay( function(text) { console.log(text); }, 1000, 'later' 阅读全文
posted @ 2021-04-09 12:00 czfeng 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 151.数组中某元素出现的次数 /** * @param { array } arr * @param {*} value */ export function countOccurrences(arr, value) { return arr.reduce((a, v) => v value ? 阅读全文
posted @ 2021-04-09 11:58 czfeng 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 121.cookie 获取 /** * @param {String} key 属性 */ export const cookieGet = (key) => { const cookieStr = unescape(document.cookie); const arr = cookieStr.s 阅读全文
posted @ 2021-04-09 11:57 czfeng 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 91.返回当前url export const currentURL = () => window.location.href; 92.获取url参数(第一种) /** * @param {*} name * @param {*} origin */ export function getUrlPa 阅读全文
posted @ 2021-04-09 11:55 czfeng 阅读(114) 评论(0) 推荐(0) 编辑
摘要: 61.验证linux"文件"路径 /** @param { string } value */ export const isLinuxFilePath = value => /^(\/[^/]+)+$/g.test(value); 62.验证window"文件夹"路径 /** @param { s 阅读全文
posted @ 2021-04-09 11:54 czfeng 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 31.从对象中选取对应于给定键的键值对 // pick: 从对象中选取对应于给定键的键值对 // 使用Array.reduce()将筛选/选取的密钥转换回具有相应键值对的对象 (如果在 obj 中存在该键)。 let pick = (obj, arr) => arr.reduce((acc, cur 阅读全文
posted @ 2021-04-09 11:52 czfeng 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 1.匹配正整数 // 匹配正整数 let isPositiveNum = val => { return /^[1-9]d*$/.test(val); }; console.log(isPositiveNum(9)) //true console.log(isPositiveNum(2.2)) // 阅读全文
posted @ 2021-04-09 11:49 czfeng 阅读(143) 评论(0) 推荐(0) 编辑