let Bonus = { 'A': (salary) => { return salary * 2 }, 'B': (salary) => { return salary * 1.8 }, 'C': (salary) => { return salary * 1.6 }, 'D': (salary) => { return salary * 1 }, 'E': (salary) => { return salary * 0.8 } } function getBonus(level, salary) { return Bonus[level](salary) }
console.log(getBonus('A', 8000)); console.log(getBonus('B', 8000)); console.log(getBonus('C', 8000)); console.log(getBonus('D', 8000)); console.log(getBonus('E', 8000));
// data let list = [{ title: 'gl', type: 1 }, { title: 'cq', type: 1 }, { title: 'sh', type: 1 }, { title: 'nj', type: 1 }, { title: 'gz', type: 1 }, { title: 'xm', type: 2 }, { title: 'fs', type: 2 }, { title: 'hk', type: 2 }, { title: 'dg', type: 3 }] // strategy let flag = { 1: { className: 'pass' }, 2: { className: 'fail' }, 3: { className: 'todo' } } // render news.innerHTML = list.map(item => { return `<li class='${flag[item.type].className}'>${item.title}</li>` }).join('')