题意: 1431. 拥有最多糖果的孩子
题解: 运用filter()方法将不满足条件的过滤
/**
* @param {number[]} candies
* @param {number} extraCandies
* @return {boolean[]}
*/
var kidsWithCandies = function(candies, extraCandies) {
let res = new Array;
for(let i = 0;i < candies.length;i++){
let re = candies.filter(item => item > (candies[i] + extraCandies)); //过滤不符合条件的数组
if(Object.keys(re).length !== 0){
res.push(false);
}else{
res.push(true);
}
}
return res;
};
题意: 1108. IP 地址无效化
题解:
/**
* @param {string} address
* @return {string}
*/
var defangIPaddr = function(address) {
return address.replaceAll('.', '[.]');
};