当前位置:网站首页>【策略模式】就像诸葛亮的锦囊
【策略模式】就像诸葛亮的锦囊
2022-07-25 09:32:00 【InfoQ】
function getPrice(originalPrice, status) {
if (status === 'pre-sale') { // 预售打 8 折
return originalPrice * 0.8
}
if (status === 'promotion') { // 促销打 9 折或者便宜 20
if (origialPrice <= 100) {
return origialPrice * 0.9
} else {
return originalPrice - 20
}
}
if (status === 'black-friday') { // 周五有多种打折策略
if (origialPrice >= 100 && originalPrice < 200) {
return origialPrice - 20
} else if (originalPrice >= 200) {
return originalPrice - 50
} else {
return originalPrice * 0.8
}
}
if (status === 'default') { // 默认不打折
return originalPrice
}
}
function preSalePrice(origialPrice) { // 预售打 8 折
return originalPrice * 0.8
}
function promotionPrice(origialPrice) { // 促销打 9 折或者便宜 20
if (origialPrice <= 100) {
return origialPrice * 0.9
} else {
return originalPrice - 20
}
}
function blackFridayPrice(origialPrice) { // 周五有多种打折策略
if (origialPrice >= 100 && originalPrice < 200) {
return origialPrice - 20
} else if (originalPrice >= 200) {
return originalPrice - 50
} else {
return originalPrice * 0.8
}
}
function defaultPrice(origialPrice) { // 默认不打折
return origialPrice
}
let priceStrategies = { // 打折策略
'pre-sale': preSalePrice,
'promotion': promotionPrice,
'black-friday': blackFridayPrice,
'default': defaultPrice
}
function getPrice(originalPrice, status) { // 根据策略获取价格
return priceStrategies[status](originalPrice)
}


边栏推荐
- 使用Three.js实现炫酷的赛博朋克风格3D数字地球大屏
- DHCP configuration (take Huawei ENSP as an example)
- Mysql离线部署
- Angr (VI) -- angr_ ctf
- For cycle: daffodil case
- Angr (III) - angr_ ctf
- Set up lnmp+discuz Forum
- Angr (VIII) -- angr_ ctf
- TCP transmission
- When installing mysql, string the service installation failure > mysql80 startup failure
猜你喜欢

Reproduce asvspoof 2021 baseline rawnet2

DHCP configuration (take Huawei ENSP as an example)

Erlang(离线部署)

Virtual private line network deployment

VS Code 连接远程 Jupyter 服务器

Angr (II) -- angr_ ctf

Angr(七)——angr_ctf

Duplicate SSL_ Anti spoofing, spoofing attacks and deep forgery detection using wav2vec 2.0 and data enhanced automatic speaker authentication

Angr(六)——angr_ctf

5.这简单的 “echo” 用法隔壁小孩能不会吗!
随机推荐
User preferences
3.跟你思想一样DNS域名解析服务!!!
Deadlock event of thread pool
Angr(二)——angr_ctf
2021 去哪儿网笔试总结
3. Believe you can understand! Circular statements and functions of shell scripts, arrays, bubble sorting
测试基本概念
Bug分类和定级
Virtual private line network deployment
MySQL offline deployment
Pytorch code template (CNN)
2021 牛客网笔试总结 02
4.隔壁小孩都会的,各种shell符号{}[]等
语音自监督预训练模型 CNN Encoder 调研总结
Trojang attack on neural networks paper reading notes
Notes on building dompteur container
Frp反向代理部署
1.Shell编程规范与变量
CONDA configures the deep learning environment pytorch transformers
21. Merge Two Sorted Lists