将字符串中的字符 &<>" (双引号), 以及 '(单引号)转换为它们对应的 HTML 实体。

现在这个表里找出要转化的符号https://dev.w3.org/html5/html-author/charref

function convert(str) {
var obj={
"&":'&amp;',
'<':'&lt;',
'>':'&gt;',
'"':'&quot;',
"'":'&apos;'
};
var arr = str.split("");
var result = arr.map(function(val){
if(obj.hasOwnProperty(val)){
return obj[val];
}else{
return val;
}
});
return result.join("");
}
convert("Dolce & Gabbana");

freeCodeCamp:Convert HTML Entities的更多相关文章

  1. FCC-学习笔记 Convert HTML Entities

    FCC-学习笔记  Convert HTML Entities 1>最近在学习和练习FCC的题目.这个真的比较的好,推荐给大家. 2>中文版的地址:https://www.freecode ...

  2. Convert HTML Entities

    function convert(str) { // :) //return str; var HTML_Entities = { '&':'&', '<':'<', '& ...

  3. FreeCodeCamp 中级算法(个人向)

    freecodecamp 中级算法地址戳这里 Sum All Numbers in a Range 我们会传递给你一个包含两个数字的数组.返回这两个数字和它们之间所有数字的和. function su ...

  4. Convert HTML Entities-freecodecamp算法题目

    Convert HTML Entities 1.要求 将字符串中的字符 &.<.>." (双引号), 以及 ' (单引号)转换为它们对应的 HTML 实体. 2.思路 利 ...

  5. FCC-js算法题解题笔记

    题目链接:https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm ...

  6. PHP清理跨站XSS xss_clean 函数 整理自codeigniter Security

    PHP清理跨站XSS xss_clean 函数 整理自codeigniter Security 由Security Class 改编成函数xss_clean 单文件直接调用.BY吠品. //来自cod ...

  7. ABP框架系列之十五:(Caching-缓存)

    Introduction ASP.NET Boilerplate provides an abstraction for caching. It internally uses this cache ...

  8. GeSHi Documentation

    GeSHi Documentation Version 1.0.8.11 Authors: © 2004 - 2007 Nigel McNie © 2007 - 2012 Benny Baumann ...

  9. FCC编程题之中级算法篇(中)

    介绍 接着上次的中级算法题 目录 1. Missing letters 2. Boo who 3. Sorted Union 4. Convert HTML Entities 5. Spinal Ta ...

随机推荐

  1. HITAG 1/2/S

    HITAG S -- 3rd generation HITAG™ family Modulation Read/Write Device to Transponder: 100 % ASK and B ...

  2. HTTP状态码通常分为5种类型

    HTTP状态码通常分为5种类型,分别以1-5五个数字开头,由3位整数组成: -------------------------------------------------------------- ...

  3. 我的javascript学习之路(一)对象之基础

    做了2个多月的ajax项目,对js的学习觉得了深入了不少,把自己的一些学习的经验贴出来,希望对初学者有所帮助,也希望大家能指出我的错误之处或者不当之处. javascript 是基于对象的语言,为什么 ...

  4. IOS 7 Study - Displaying an Image on a Navigation Bar

    ProblemYou want to display an image instead of text as the title of the current view controlleron th ...

  5. Educational Codeforces Round 7 E. Ants in Leaves 贪心

    E. Ants in Leaves 题目连接: http://www.codeforces.com/contest/622/problem/E Description Tree is a connec ...

  6. CodeForces 173C Spiral Maximum 记忆化搜索 滚动数组优化

    Spiral Maximum 题目连接: http://codeforces.com/problemset/problem/173/C Description Let's consider a k × ...

  7. cdoj 03 BiliBili, ACFun… And More! 水题

    Article Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/3 Descr ...

  8. rqnoj-217-拦截导弹-最长不上升子序列以及不上升子序列的个数

    最长上升子序列的O(n*log(n))算法. 不上升子序列的个数等于最长上升子序列的长度. #include<string.h> #include<stdio.h> #incl ...

  9. [AngularJS+ GSAP] Greensock TimelineLite Animation Sequences

    TimelineLite is a piece of the Greensock TweenMax library that provides the ability to create sequen ...

  10. Java生成 Word文档的并打印解决方案

    户要求用程序生成标准的word文档,要能打印,而且不能变形,以前用过很多解决方案,都在客户严格要求下牺牲的无比惨烈. POI读word文档还行,写文档实在不敢恭维,复杂的样式很难控制不提,想象一下一个 ...