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 ...
随机推荐
- 一张图告诉你,只会这些HTML还远远不够!!!!!
不知道自己HTML水平如何,不知道HTML5如何进化?看这张图 如果一半以上的你都不会,必须看这本书,阿里一线工程师用代码和功能页面来告诉你每一个技术点. 都会一点,但不知道如何检验自己,看看本书提供 ...
- Objective-C Numbers
In Objective-C programming language, in order to save the basic data types like int, float, bool in ...
- Android View 背景选择器编写技巧
在项目中选择器的使用是非常多的,以下是本人在项目中的一些常用的背景选择器的写法 带边框下划线背景选择器效果图: 上面布局中放了10个CheckBox,然后设置了CheckBox的背景图片位,背景选择器 ...
- # Volley源码解析(二) 没有缓存的情况下直接走网络请求源码分析#
Volley源码解析(二) 没有缓存的情况下直接走网络请求源码分析 Volley源码一共40多个类和接口.除去一些工具类的实现,核心代码只有20多个类.所以相对来说分析起来没有那么吃力.但是要想分析透 ...
- HDU 5469 Antonidas (树形DP,暴力)
题意: 给一棵n节点的树图,每个点都是一个小写字母,要求找到两个点(a,b),从a->b的路径上形成了一个字符串为s.给出s,问是否存在这样的点对. 思路: 考虑一个点,要么从该点出发,要么在该 ...
- Spring IOC模块的简单介绍
首先,本人正在学习spring,这是一点心得体会,所以本文中会有不足.错误之处,欢迎各位大佬进行指点. 其次对于框架而言,知道反射是很重要,所以建议在学会反射了后在去看看框架. Spring:是企业级 ...
- Tarjan求强联通分量+缩点
提到Tarjan算法就不得不提一提Tarjan这位老人家 Robert Tarjan,计算机科学家,以LCA.强连通分量等算法闻名.他拥有丰富的商业工作经验,1985年开始任教于普林斯顿大学.Tarj ...
- NLP.TM | GloVe模型及其Python实现
在进行自然语言处理中,需要对文章的中的语义进行分析,于是迫切需要一些模型去描述词汇的含义,很多人可能都知道word2vector算法,诚然,word2vector是一个非常优秀的算法,并且被广泛运用, ...
- HashMap允许将null用作键 也允许将null作为值
HashMap不能保证元素的顺序,HashMap能够将键设为null,也可以将值设为null. 与之对应的是Hashtable,(注意大小写:不是HashTable),Hashtable不能将键和值设 ...
- ELK踩过的各种坑 6.4版本
一.elasticsearch 1.服务正常启动,但不能正常访问 [root@linux-node1 elasticsearch]# systemctl start elasticsearch [ro ...