Repeat Array Generator

RepeatArrayGenerator


"use strict"; /**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
*
* @description Repeat Array
* @augments
* @example
*
*/ const RepeatArrayGenerator = (datas = [], num = 1, debug = false) => {
let result = ``;
// do something...
let str = `${datas.toString()},`;
str = str.repeat(num);
str = str.slice(0, str.length -1);
result = str.split(`,`);
return result;
}; export default RepeatArrayGenerator;
const RepeatArray = RepeatArrayGenerator;
export {
RepeatArrayGenerator,
RepeatArray
}; /* let data = [12, 19, 3, 5, 2, 3, 12, 9, 3, 15]; const datas = RepeatArrayGenerator(data, 10);
// ["3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19"] */

Repeat Array Generator


"use strict"; /**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
*
* @description Repeat Array
* @augments
* @example
*
*/ const RepeatArrayGenerator = (datas = [], num = 1, debug = false) => {
let result = "";
let str = `${datas.toString()},`;
str = str.repeat(num);
str = str.slice(0, str.length - 1);
result = str.split(`,`);
result = result.map(item => {
let newItem = "";
newItem = (item.trim() !== "") ? parseFloat(item) : "";
return newItem;
});
if (debug) {
console.log(`result =\n`, result);
}
return result;
}; export default RepeatArrayGenerator;
const RepeatArray = RepeatArrayGenerator;
export {
RepeatArrayGenerator,
RepeatArray
}; /* let data = [12, 19, 3, 5, 2, 3, 12, 9, 3, 15]; const datas = RepeatArrayGenerator(data, 10);
// ["3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19", "3", "5", "2", "3", "12", "9", "3", "15", "12", "19"] */

null


const RA = (datas = [], num = 1, debug = false) => {
let result = "";
let str = `${datas.toString()},`;
str = str.repeat(num);
str = str.slice(0, str.length - 1);
result = str.split(`,`);
result = result.map(item => {
let newItem = "";
if (item !== "") {
newItem = (item.trim() !== "") ? parseFloat(item) : "";
}else {
newItem = null;
}
return newItem;
});
if (debug) {
console.log(`result =\n`, result);
}
return result;
}; let a = [null]; RA(a, 3); // [null, null, null]

OK

Repeat Array Generator & String.repeat的更多相关文章

  1. FreeCodecamp:Repeat a string repeat a string

    要求: 重要的事情说3遍! 重复一个指定的字符串 num次,如果num是一个负数则返回一个空字符串. 结果: repeat("*", 3) 应该返回"***". ...

  2. Repeat a string repeat a string-freecodecamp算法题目

    Repeat a string repeat a string(重复输出字符串) 要求 重复一个指定的字符串 num次 如果num是一个负数则返回一个空字符串. 思路 将给定的字符串赋给定义的变量te ...

  3. JavaScript string repeat methods All In One

    JavaScript string repeat methods All In One There are many ways in the ES-Next ways repeat ES2015 / ...

  4. mongodb 更新数组出现can't append to array using string field name

    数据库内容大概如下: { _id:, "hero_list" : { " : { , , "equip" : [ [ ], [ ], [ ], { , ...

  5. curl Array to string conversion 错误

    0x00 故障 由于GuzzleHttp在iis上使用错误,于是开始替换其为Unirest,没想到发送了一个curl Array to string conversion 错误 0x01 原因 跟踪调 ...

  6. golang array, slice, string笔记

    本来想写一篇关于golang io的笔记,但是在学习io之前必须了解array, slice, string概念,因此将在下篇写golang io.   array: 数组的长度是该数组类型的一部分, ...

  7. js & array to string

    js & array to string https://stackoverflow.com/questions/13272406/convert-string-with-commas-to- ...

  8. Notice:Array to string conversion的问题

    如果后台或者前端输出这样的提示: Notice: Array to string conversion 原因是:用 echo  来输出数组,当然会报错,数组应该用print , print_r , 或 ...

  9. php报错Array to string conversion 解决方案,动态输出数据库列名称

    php报错Array to string conversion 解决方案,动态输出数据库列名称 问题:在Windows php5.3环境下使用:<?php echo $row->$keys ...

随机推荐

  1. 小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载二(生命周期)

    4.1 什么是生命周期 想要真正地理解PhoneGap应用开发的内涵,首先需要理解什么是生命周期.这在字面上其实非常容易理解,一个应用从开始运行被手机加载到应用被退出之间的过程就称之为一个生命周期.为 ...

  2. 88E1111

    千兆网phy芯片 支持GMII,RGMII,MII等接口 具备4个GMII时钟模式 支持自适应功能 超低功耗模式 功率降低模式 MDC/MDIO/TWSI接口 支持10Mb/s,100Mb/s,100 ...

  3. .Net Mvc 返回Json,动态生成EasyUI Tree

    最近做一个项目,开始接触EasyUI,感觉很强大,很适合我这种对前台不是很感冒的人.在学习Tree的过程中,感觉网上的资料挺乱的,很多只是把EasyUI API 抄了一遍.现在把最近这段时间的学到的, ...

  4. 【算法基础】欧几里得gcd求最大公约数

    package Basic; import java.util.Scanner; public class Gcd { public static void main(String[] args) { ...

  5. 关于CSS3三角的实现

    1,向上的三角 ;;           ;;           </html> 3,向左的三角 ;;           </html> 4,向右的三角 ;;        ...

  6. Android 使用 adb命令 远程安装apk

    Android 使用 adb命令 远程安装apk ./adb devices 列出所有设备 ./adb connect 192.168.1.89 连接到该设备 ./adb logcat 启动logca ...

  7. iptables(1)工具详解

    一. iptables 查看链表,创建链表,类命令 1. iptables [-t table] -N chain : 创建一条自定义规则的链 1 2     # iptables -t filter ...

  8. 51nod——1174 区间中最大的数(ST)

    题目链接 给出一个有N个数的序列,编号0 - N - 1.进行Q次查询,查询编号i至j的所有数中,最大的数是多少. 例如: 1 7 6 3 1.i = 1, j = 3,对应的数为7 6 3,最大的数 ...

  9. django-ckeditor添加代码功能(codesnippet)

    最近做了一个博客,使用python3+django2.1开发的,后台编辑器和前端显示用的Django-ckeditor富文本编辑器,由于发现没有代码块功能,写上去的代码在前端展示有点乱,于是一顿问度娘 ...

  10. dom4j 常用操作

    package com.wanbang.wbyyb.common.util; import com.alibaba.fastjson.JSONObject; import com.wanbang.wb ...