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. [Luogu1343]地震逃生 最大流

    题目链接:https://www.luogu.org/problem/show?pid=1343 dinic跑最大流. #include<cstdio> #include<cstri ...

  2. ES-windos环境搭建(1)

    前言 由于elasticsearch为Java开发,所以它还依赖Java JDK环境,并且对版本还有要求,需要1.8(含)以上.我们首先来配置Java JDK环境. JDK简介 JDK是Java语言的 ...

  3. THML5新增功能

    HTML5新增功能 1.语义化标记: 1)article:article标签装载显示一个独立的文章内容.例如一篇完整的论坛帖子,一则网站新闻,一篇博客文章等等,一个用户评论等等 artilce可以嵌套 ...

  4. Volley源码解析(三) 有缓存机制的情况走缓存请求的源码分析

    Volley源码解析(三) 有缓存机制的情况走缓存请求的源码分析 Volley之所以高效好用,一个在于请求重试策略,一个就在于请求结果缓存. 通过上一篇文章http://www.cnblogs.com ...

  5. 使用POI创建word表格合并单元格兼容wps

    poi创建word表格合并单元格代码如下: /** * @Description: 跨列合并 */ public void mergeCellsHorizontal(XWPFTable table, ...

  6. Bootstrap 入门到精通

    介绍 Bootstrap,来自 Twitter,是目前最受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷.Bootstr ...

  7. python基础一 day14 生成器函数进阶

    def generator(): print(123) content = yield 1 print('=======',content) print(456) arg = yield 2 '''' ...

  8. 系统学习爬虫_2_urllib

    什么是urllib urlopen urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=None, cad ...

  9. 一款App的开发成本是多少?

    答一: 接触过上万名创业者,开发上线过超过30款App,没有比我更适合回答这个问题的了.. 本文对想做好一款App项目的人来说这是一篇价值百万的回答!因为这是我们花了几百万试错成本试出来的经验! &l ...

  10. 配置SpringMVC返回JSON遇到的坑

    坑一:官方网站下载地址不明朗,最后找了几个下载地址:http://wiki.fasterxml.com/JacksonDownload Jackson2.5下载地址:jackson2.5.0.jar ...