好玩的线上检测代码工具-codewars(3)
来源:互联网 发布:手机知乎如何关注话题 编辑:程序博客网 时间:2024/05/01 11:54
Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore (‘_’).
Examples:
solution(‘abc’) // should return [‘ab’, ‘c_’]
solution(‘abcdef’) // should return [‘ab’, ‘cd’, ‘ef’];
function solution($str) { //每两个字符为一个单位,重新放到新的数组中 if(strlen($str) == 0) { return []; } $new_str = ''; if(strlen($str) % 2 == 0) { $new_str = $str; } else{ $new_str = $str . '_'; } return str_split($new_str, 2); //切割字符串,并返回数组}
阅读全文
0 0
- 好玩的线上检测代码工具-codewars(3)
- 好玩的线上检测代码工具-codewars(1)
- 好玩的线上检测代码工具-codewars(2)
- 好玩的线上检测代码工具-codewars(4)
- 好玩的线上检测代码工具-codewars(5)
- 一段好玩的代码
- 好玩的java代码
- 一段好玩的代码
- 好玩的代码
- 前端开发调试线上代码的两款工具
- 好玩的webapp工具maka
- 呼唤QQ的代码,好玩
- 好玩的代码注释模板
- 【总结】一些好玩的工具汇总
- 辣子工具LSUtils:一些好玩的函数
- 一段好玩的修改网页的代码
- 好玩的代码读你的心
- 一道好玩的题的解题代码
- 浅谈 EF CORE 迁移和实例化的几种方式
- layui通用单图上传的方法
- 微信屏蔽朋友圈、分享给朋友、隐藏“传播类”和“保护类”按钮 不引weixin.js
- epoll和select的区别
- ART Dalvik
- 好玩的线上检测代码工具-codewars(3)
- 《西瓜书》笔记11:特征选择方法(一)
- 笨办法学 Python · 续 练习 38:SQL 简介
- 每个APP都会用到的LoadingLayout
- [人工智能]AI移动自动化测试
- android--分段录制视频
- Android开发 之 确认凭证
- import moviepy 报错
- Java IOC和AOP解析