猿问

javascript的题目求解

请大家看一下,这个应该怎么解决

https://img1.mukewang.com/5bc002f6000126c003240350.jpg

扬帆大鱼
浏览 515回答 1
1回答

慕哥6287543

看起来没啥难度啊,不知道你是哪里搞不懂?不如把你的代码贴出来分析下es6 语法const convert = (() => {&nbsp; &nbsp; var rules = [&nbsp; &nbsp; &nbsp; &nbsp; [/&/g, "&amp;"],&nbsp; &nbsp; &nbsp; &nbsp; [/</g, "&lt;"],&nbsp; &nbsp; &nbsp; &nbsp; [/>/g, "&gt;"],&nbsp; &nbsp; &nbsp; &nbsp; [/"/g, "&quot;"],&nbsp; &nbsp; &nbsp; &nbsp; [/'/g, "&apos;"]&nbsp; &nbsp; ];&nbsp; &nbsp; return function(s) {&nbsp; &nbsp; &nbsp; &nbsp; return rules.reduce((s, rule) => {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return s.replace(rule[0], rule[1]);&nbsp; &nbsp; &nbsp; &nbsp; }, s);&nbsp; &nbsp; };})();// testing[&nbsp; &nbsp; "Dolce & Gabbana",&nbsp; &nbsp; "Hamburgers < Pizza < Taos",&nbsp; &nbsp; "Sixty > twelve",&nbsp; &nbsp; "Stuff in \"quotation marks\"",&nbsp; &nbsp; "Shindler's List",&nbsp; &nbsp; "<>",&nbsp; &nbsp; "abc"].forEach(s => console.log(convert(s)));
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答