好玩的线上检测代码工具-codewars(4)
来源:互联网 发布:优酷会员淘宝不能买了 编辑:程序博客网 时间:2024/05/22 08:27
You are going to be given a word. Your job is to return the middle character of the word. If the word’s length is odd, return the middle character. If the word’s length is even, return the middle 2 characters.
Examples:
Kata.getMiddle(“test”) should return “es”
Kata.getMiddle(“testing”) should return “t”
Kata.getMiddle(“middle”) should return “dd”
Kata.getMiddle(“A”) should return “A”
Input
A word (string) of length 0 < str < 1000 (In javascript you may get slightly more than 1000 in some test cases due to an error in the test cases). You do not need to test for this. This is only here to tell you that you do not need to worry about your solution timing out.
Output
The middle character(s) of the word represented as a string.
function getMiddle($text) { $len = strlen($text); if($len <= 0 || $len >= 1000) { return ''; } //偶数直接返回两个字符 if($len % 2 == 0) { return substr($text, $len/2-1, 2); } else { return substr($text, floor($len/2), 1); }}
- 好玩的线上检测代码工具-codewars(4)
- 好玩的线上检测代码工具-codewars(1)
- 好玩的线上检测代码工具-codewars(2)
- 好玩的线上检测代码工具-codewars(3)
- 好玩的线上检测代码工具-codewars(5)
- 一段好玩的代码
- 好玩的java代码
- 一段好玩的代码
- 好玩的代码
- 前端开发调试线上代码的两款工具
- 好玩的webapp工具maka
- 呼唤QQ的代码,好玩
- 好玩的代码注释模板
- 【总结】一些好玩的工具汇总
- 辣子工具LSUtils:一些好玩的函数
- 一段好玩的修改网页的代码
- 好玩的代码读你的心
- 一道好玩的题的解题代码
- IT 岗位版《王者荣耀》,告诉我你是农药里的谁?
- Maven阿里云镜像地址
- STM32一直死在r1,[r0,#0x808]
- 理解cout“从右至左入栈”
- Python高级之——浅拷贝、深拷贝(deepcopy、copy的区别)
- 好玩的线上检测代码工具-codewars(4)
- log4j2配置日志文件以时间方式显示
- webpack解惑:require的五种用法
- 【HDU
- java基础学习总结——基础语法1
- angular学习笔记(二)
- Oracle的Sql语句一些知识点(2)
- HDU-2017"百度之星"程序设计大赛-初赛(B)-1002-Factory
- grep命令使用-正则表达式(zz)