implement sum
sum() {
}
console.log(sum(2,1,3));
Legacy
function sum() {
const args = arguments;
let res = 0;
for (let i=0; i<args.length; i++) {
res += args[i];
}
return res;
}
console.log(sum(2,1,3));
Functions Rest Parameters
function sum(...args) {
return args.reduce((pre, cur) => pre + cur, 0);
}
console.log(sum(2,1,3));
Contains case insensitive
const a = "This is a test";
const b = "IS";
a.toLowerCase().includes(b.toLowerCase())
!!a.match(new RegExp(b, "i"));
new RegExp(b, "i").test(a)
implement delay(ms)
const delay = (ms) => new Promise(res => setTimeout(res, ms))
function delay(milisec) {
return new Promise(resolve => {
setTimeout(() => { resolve('') }, milisec);
})
}