Repeat Array Generator & String.repeat
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的更多相关文章
- FreeCodecamp:Repeat a string repeat a string
要求: 重要的事情说3遍! 重复一个指定的字符串 num次,如果num是一个负数则返回一个空字符串. 结果: repeat("*", 3) 应该返回"***". ...
- Repeat a string repeat a string-freecodecamp算法题目
Repeat a string repeat a string(重复输出字符串) 要求 重复一个指定的字符串 num次 如果num是一个负数则返回一个空字符串. 思路 将给定的字符串赋给定义的变量te ...
- 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 / ...
- mongodb 更新数组出现can't append to array using string field name
数据库内容大概如下: { _id:, "hero_list" : { " : { , , "equip" : [ [ ], [ ], [ ], { , ...
- curl Array to string conversion 错误
0x00 故障 由于GuzzleHttp在iis上使用错误,于是开始替换其为Unirest,没想到发送了一个curl Array to string conversion 错误 0x01 原因 跟踪调 ...
- golang array, slice, string笔记
本来想写一篇关于golang io的笔记,但是在学习io之前必须了解array, slice, string概念,因此将在下篇写golang io. array: 数组的长度是该数组类型的一部分, ...
- js & array to string
js & array to string https://stackoverflow.com/questions/13272406/convert-string-with-commas-to- ...
- Notice:Array to string conversion的问题
如果后台或者前端输出这样的提示: Notice: Array to string conversion 原因是:用 echo 来输出数组,当然会报错,数组应该用print , print_r , 或 ...
- php报错Array to string conversion 解决方案,动态输出数据库列名称
php报错Array to string conversion 解决方案,动态输出数据库列名称 问题:在Windows php5.3环境下使用:<?php echo $row->$keys ...
随机推荐
- pyhton中的__new__和__init__
首先__new__() 函数只能用于从object继承的新式类:其次,object将__new__()方法定义为静态方法,并且至少需要传递一个参数cls,cls表示需要实例化的类,此参数在实例化时由P ...
- sqlserver中drop、truncate和delete语句的用法
虽然小编不建议大家去用命令删除数据库表中的东西,但是这些删除命令总有用的着的地方. 说到删除表数据的关键字,大家记得最多的可能就是delete了 然而我们做数据库开发,读取数据库数据.对另外的两兄弟用 ...
- 使用javap分析Java的字符串操作
我们看这样一行简单的字符串赋值操作的Java代码. String a = "i042416"; 使用命令行将包含了这行代码的Java类反编译查看其字节码: javap -v con ...
- idea 发布和本地测试问题
1.maven本地打包成jar 提示[错误: 找不到或无法加载主类]修改 配置maven ---->Runner---->VM Optins [-DarchetypeCatalog=loc ...
- Python-OpenCV:cv2.imread(),cv2.imshow(),cv2.imwrite()
为什么使用Python-OpenCV? 虽然python 很强大,而且也有自己的图像处理库PIL,但是相对于OpenCV 来讲,它还是弱小很多.跟很多开源软件一样OpenCV 也提供了完善的pytho ...
- sort函数的使用
此篇当作自己的笔记(水平太菜,这都一直没搞明白) sort()函数的用法1)sort函数包含在头文件<algroithm>中,还要结合using namespace std2)sort有三 ...
- 2010: C语言实验——逆置正整数
2010: C语言实验——逆置正整数 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 949 Solved: 691[Submit][Status][We ...
- 【图文并茂】DEV配置NTL库
一开始根据陈老师的博客:再说如何在DEV C++中搭建NTL库 后来发现自己虽然跟着一步一步来做,还是做错了很多回. 究竟怎么一回事呢?后来我发现一个致命的错误很容易忽视,所以我就重新写一篇博客. 来 ...
- Linux系统分区 进程管理 软件包安装
对于一块新的磁盘来说,系统能够使用需要有分区.格式化文件系统.挂载等主要操作,下面通过命令的方式对一块磁盘进行操作. 一. Linux系统分区 1.1 在虚拟机开机前选择虚拟机配置,添加一个新的SCS ...
- 实验十一 团队作业7:团队项目设计完善&编码
实验十一 团队作业7:团队项目设计完善&编码 实验时间 2019-6-6 Deadline: 2019-6-12 10:00,以团队随笔博文提交至班级博客的时间为准. 评分标准: 按时交 – ...