Reverse a String-freecodecamp算法题目
Reverse a String(翻转字符串)
- 题目要求:
- 把字符串转化成数组
- 借助数组的reverse方法翻转数组顺序
- 把数组转化成字符串
- 思路:
- 用.split('')将字符串转换成单个字母组成的数组
- 用.reverse()把数组反转
- 用.join('')把数组元素连接成字符串
- 代码如下:
-
function reverseString(str) {
// 请把你的代码写在这里
var temp = [];
temp = str.split("");
temp = temp.reverse();
str = temp.join("");
return str;
} reverseString("hello");
-
- 相关链接
- .split()方法:http://www.runoob.com/jsref/jsref-split.html
- .reverse()方法:http://www.runoob.com/jsref/jsref-reverse.html
- .join()方法:http://www.runoob.com/jsref/jsref-join.html
- 说明:
- 本人非计算机专业,大学有学过C语言(谭浩强的书)的课程。
- 学习前端是在Freecodecamp学习的。目前已拿到前端开发证书。我的Freecodecamp主页:https://www.freecodecamp.cn/ahswch
- fcc系列博客是我在学完fcc前端课程后对做过的算法系列题目的一个总结。
- 博客中如有知识错误,敬请指正。
Reverse a String-freecodecamp算法题目的更多相关文章
- Map the Debris -freecodecamp算法题目
Map the Debris 1.要求 返回一个数组,其内容是把原数组中对应元素的平均海拔转换成其对应的轨道周期. 原数组中会包含格式化的对象内容,像这样 {name: 'name', avgAlt: ...
- Spinal Tap Case -freecodecamp算法题目
Spinal Tap Case 1.要求 将字符串转换为 spinal case. Spinal case 是 all-lowercase-words-joined-by-dashes 这种形式的,也 ...
- Search and Replace -freecodecamp算法题目
Search and Replace 1.要求 使用给定的参数对句子执行一次查找和替换,然后返回新句子. 第一个参数是将要对其执行查找和替换的句子. 第二个参数是将被替换掉的单词(替换前的单词). 第 ...
- LeetCode算法题目解答汇总(转自四火的唠叨)
LeetCode算法题目解答汇总 本文转自<四火的唠叨> 只要不是特别忙或者特别不方便,最近一直保持着每天做几道算法题的规律,到后来随着难度的增加,每天做的题目越来越少.我的初衷就是练习, ...
- reverse the string word by word
题目:Given an input string, reverse the string word by word. For example,Given s = "the sky is bl ...
- LeetCode 5:Given an input string, reverse the string word by word.
problem: Given an input string, reverse the string word by word. For example: Given s = "the sk ...
- [优化]Steamroller-freecodecamp算法题目
晚上在medium看到一篇关于找工作的文章,里面提到一个面试题目--flattening an array(扁平化数组).这我好像在哪看过!应该是freecodecamp里的算法某一题.翻了下博客记录 ...
- PTA数据结构与算法题目集(中文) 7-43字符串关键字的散列映射 (25 分)
PTA数据结构与算法题目集(中文) 7-43字符串关键字的散列映射 (25 分) 7-43 字符串关键字的散列映射 (25 分) 给定一系列由大写英文字母组成的字符串关键字和素数P,用移位法定义 ...
- PTA数据结构与算法题目集(中文) 7-42整型关键字的散列映射 (25 分)
PTA数据结构与算法题目集(中文) 7-42整型关键字的散列映射 (25 分) 7-42 整型关键字的散列映射 (25 分) 给定一系列整型关键字和素数P,用除留余数法定义的散列函数将关键字映射 ...
随机推荐
- UDP client,UDP server, TCP server, TCP client
UDP server import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocke ...
- Ubuntu Cloud Image in Openstack
Ubuntu出的云环境镜像(http://uec-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img),已经 ...
- SQLAlchemy的使用---查询的更多操作
# 查询更多操作 from create_table import User, engine from sqlalchemy.orm import sessionmaker Session = ses ...
- Python爬虫之requests模块(2)
一.今日内容 session处理cookie proxies参数设置请求代理ip 基于线程池的数据爬取 二.回顾 xpath的解析流程 bs4的解析流程 常用xpath表达式 常用bs4解析方法 三. ...
- Android 使用RecyclerView优雅实现悬浮标题通讯录
项目地址:https://github.com/hgDendi/ContactsList 界面概览: ContactsListDemo ContactsListDemo2 概要 如图,主要简单划分为两 ...
- user purchase behavior:
user purchase behavior: 参考网址: online shopping frequent https://www.bigcommerce.com/blog/ecommerce-tr ...
- EL表达式的内置对象
在EL表达式中,无需创建就可以使用的对象称之为EL隐藏(隐含.内置)对象.在EL中一共有11个隐藏对象,它们都与Map相似.其中10是Map,一个是 PageContext. 参数隐藏对象 这些隐藏对 ...
- [C#] SHA1校验函数用法
首先引用这个命名空间 using System.Security.Cryptography; //建立SHA1对象 SHA1 sha = new SHA1CryptoServiceProvider() ...
- django模型详解(四)
1 概述 (1)概述 : Django对各种数据库提供了很好的支持,Django为这些数据库提供了统一的调用API,根据不同的业务需求选择不同的数据库 (2)定义模型 模型,属性,表,字段间的关系 一 ...
- python下的selenium安装
安装python 打开 Python官网,找到“Download”, 在其下拉菜单中选择自己的平台(Windows/Mac),一般的Linux平台已经自带的Python,所以不需要安装,通过打开“终端 ...