FCC-js 算法我的解题遇到的问题记录

一、返回数组中的最大最小值(参数是一组数,不是列表数组)

Math.max([value1[,value2, ...]]) 
Math.min([value1[,value2, ...]])

二、合并数组 Array.concat()返回值为建立新数组,须要赋值给变量进行使用,不会改变原有数组的值

三、函数多参数arguments转化为数组

var args = Array.prototype.slice.call(arguments);  //通用方式,不该在 arguments 对象上使用 \
                                                 //slice 方法,这会阻碍 JavaScript 引擎的优化 (好比 V8 引擎)
var args = Array.slice(arguments);  //若是 Array generics 可用的话
var args = Array.from(arguments); //推荐方式

四、常见html实体的字符替换

同理常见正则表达式的特殊字符连接:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Special_characters_in_regular_expressionsjavascript

str = str.replace(/[&]/g,"&amp;").replace(/[<]/g,"&lt;").replace(/[>]/g,"&gt;")
           .replace(/["]/g,'&quot;').replace(/[']/g,"&apos;");

五、数组元素删除,替换,插入

相关文章
相关标签/搜索