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. 洛谷 P1902 刺杀大使

    刺杀大使 一道并不难的二分题,竟让我交了上20次,诶,果然还是我太弱了. 看完题目就基本想到要怎么做了: 只需要对最小伤害代价进行二分即可,check()函数里用搜索判断是否可以到达最后一行,这里的c ...

  2. url post 请求方法

    最近的项目是给手机app 提供方法. 因此 此方法可以进行接口测试 static class HttpClient { static CookieContainer cookies = new Coo ...

  3. 安装MySQLdb出现HAVE_WCSCOLL重定义问题的解决方法

    root@wodeyitian MySQL-python-1.2.3]# python setup.py install running install running bdist_egg runni ...

  4. codevs 1277 生活大爆炸 2012年CCC加拿大高中生信息学奥赛

     时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题目描述 Description Sheldon and Leonard are physicists wh ...

  5. 解决activeandroid no such table

    场景:activeandroid拷贝数据库 (1)复制sql数据库到项目的assets目录,例如/myapp/src/main/assets/prepop.db (2)确保manifest的AA_DB ...

  6. PHP 头部utf-8

    只是自己用的一些存储,请各位看官大大勿怪. header("Content-Type: text/html;charset=utf-8"); 2019年04月10日

  7. vuejs 中 select 动态填充数据,后台的数据

           selected:"A" 对       selected:A 错.  变量不用引号. 内容一定要引号. https://jsfiddle.net/rgnuaw30/ ...

  8. vue表单验证:vee-validate中文提示

    官方文档:https://baianat.github.io/vee-validate/guide/ vee-validate可用于vue项目中进行表单验证,使用方法在官方API上都可以查到: 使用过 ...

  9. 使用Spring Cloud需要了解一些概念

    Spring Cloud是一个基于Spring Boot实现的微服务架构开发工具,它为基于JVM的微服务开发中的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全局锁.决策竞选.分布式会话和集 ...

  10. 【二分 贪心】bzoj3477: [Usaco2014 Mar]Sabotage

    科学二分姿势 Description Farmer John's arch-nemesis, Farmer Paul, has decided to sabotage Farmer John's mi ...