首页 > 其他分享 >基于lodash的实用函数

基于lodash的实用函数

时间:2023-02-17 11:00:39浏览次数:28  
标签:const lodash _. number value 实用 start prefix 函数

  • getCustomizedObject
/**
 * @number: the count of object attribute 
 * @prefix: the object attribute prefix string
 * @value: the value of each attribute, default is ''
 * @start: the default start is 1
 * Example: 
 * getCustomizedObject(3, 'amount') // {amount1:'', amount2:'', amount3:''}
 */
export const getCustomizedObject = (number, prefix, value='', start=1) => {
  const keys = _.times(number, (i)=> `${prefix}${i+start}`);
  const values = _.times(number, ()=> value);
  return _.zipObject(keys, values);
};
  • getCustomizedArray
/**
 * @number: the elment count of array
 * @prefix: the element value prefix string
 * @start: the default start is 1
 * Example: 
 * getCustomizedArray(3, 'amount', 2) // ['amount2', 'amount3', 'amount4']
 */
export const getCustomizedArray = (number, prefix, start=1) => {
  return _.times(number, (i) => `${prefix}${i+start}`);
};

标签:const,lodash,_.,number,value,实用,start,prefix,函数
From: https://www.cnblogs.com/xiaodi-js/p/17129379.html

相关文章

  • [django]钩子函数的一些细节(clean)
    函数名说明:clean_后面跟着的是需要校验字段名称示例:classRelUserReset(forms.ModelForm):defclean_confirm_password(self):pass校验顺序说明:如果是继承的......
  • [javascript]端序(endian)和Buffer对象的read|write系列函数
    假设有如下对象:varbuf=Buffer.from("Hello.\n");其保存在内存当中的形式实际上是这样的,这里我们假设该对象的内存地址从0x00开始:地址0x000x010x020x030x04......
  • python爬虫基本学习——函数(2.16博客补)
    函数概念:编写程序时,需要某块代码多次,为了提高编写效率和代码的重用,把具有独立功能的代码块组织为一个小模块,即函数。代码练习'''#函数的定义defprintinfo():pri......
  • 过滤器函数 filtes 的使用总结
    //importparseTime,formatTimeandsettofilter/***Showplurallabeliftimeispluralnumber*@param{number}time*@param{string}label*@retu......
  • VUE生命周期函数/axios与后端交互案例
    axios发送ajax请求与后端交互以后都用它,在vue上,第三方的模块Axios是一个基于promise的HTTP库,还是基于XMLHttpRequest封装的#跨越问题 -浏览器的原因,只要向不是......
  • excel vba宏 函数应用
          =IF(ISNUMBER(FIND("经济学",M1)),1,0)判断单元格m1中是否包含“经济学”,如果包含值为1,不包含值为0=IF(ISNUMBER(FIND("党员",N1)),1,0)判断单元格n1......
  • [js函数] shallowEqual
    constisBasicType=(t:any)=>{returnt==="number"||t==="string"||t==="boolean"||t==='undefined';}/***数组和对象都能比较*@parama*@pa......
  • [js函数] storageManager
    import_getfrom'lodash.get';import_setfrom'lodash.set';import_debouncefrom'lodash.debounce';import{shallowEqual}from"./shallow-equal";constIS......
  • 普通生成函数学习笔记
    现在我们考虑有一个序列\((a_1,a_2,a_3,\cdots,a_n,\cdots)\)。我们将这个序列作为形式幂级数\(A(x)=\sum_{n\ge0}{a_{n}x^n}\)的常数项序列。\(A(x)\)就是序列\(\{a......
  • Python sorted函数及用法
    orted()作为 Python 内置函数之一,其功能是对序列(列表、元组、字典、集合、还包括字符串)进行排序。sorted()函数的基本语法格式如下:list=sorted(iterable,key=None,......