The Office II - Boredom Score
์๋ฆฌ์ฆ๊ฐ ์ฌ๋ฐ๋ค. The Office 2ํ์ด๋ค.
๋ฌธ์
Every now and then people in the office moves teams or departments. Depending what people are doing with their time they can become more or less boring. Time to assess the current team.
You will be provided with an object(staff) containing the staff names as keys, and the department they work in as values.
Each department has a different boredom assessment score, as follows:
accounts = 1 finance = 2 canteen = 10 regulation = 3 trading = 6 change = 6 IS = 8 retail = 5 cleaning = 4 pissing about = 25
Depending on the cumulative score of the team, return the appropriate sentiment:
<=80: 'kill me now' < 100 & > 80: 'i can handle this' 100 or over: 'party time!!'
Sample Tests
function boredom(staff){
}
Test.describe("Example tests",_=>{
Test.assertEquals(boredom({tim: 'change', jim: 'accounts',
randy: 'canteen', sandy: 'change', andy: 'change', katie: 'IS',
laura: 'change', saajid: 'IS', alex: 'trading', john: 'accounts',
mr: 'finance' }), 'kill me now');
Test.assertEquals(boredom({ tim: 'IS', jim: 'finance',
randy: 'pissing about', sandy: 'cleaning', andy: 'cleaning',
katie: 'cleaning', laura: 'pissing about', saajid: 'regulation',
alex: 'regulation', john: 'accounts', mr: 'canteen' }), 'i can handle this');
Test.assertEquals(boredom({ tim: 'accounts', jim: 'accounts',
randy: 'pissing about', sandy: 'finance', andy: 'change',
katie: 'IS', laura: 'IS', saajid: 'canteen', alex: 'pissing about',
john: 'retail', mr: 'pissing about' }), 'party time!!');
})
๋ฌธ์ ์ดํด
boredom(
{tim: 'change',
jim: 'accounts',
randy: 'canteen',
sandy: 'change',
andy: 'change',
katie: 'IS',
laura: 'change',
saajid: 'IS',
alex: 'trading',
john: 'accounts',
mr: 'finance'}
)
boredom์ด๋ผ๋ ํจ์์ ์ธ์๋ก ๊ฐ์ฒด๊ฐ ๋ค์ด์จ๋ค. ๋งค๊ฐ๋ณ์๋ช ์ staff์ด๋ค. staff ๊ฐ์ฒด์ key๋ ์คํํ์ ์ด๋ฆ์ด๊ณ , value๋ ๋ถ์๋ช ์ด ๋๋ค. ์ด ๋ถ์๋ช ์ ์ญํ ์ด ํน๋ณํ๋ค.
accounts = 1
finance = 2
canteen = 10
regulation = 3
trading = 6
change = 6
IS = 8
retail = 5
cleaning = 4
pissing about = 25
์ด๋ ๊ฒ ์ ์๋ฅผ ๋ํ๋ธ๋ค.
์ ์ฒด ์คํํ๊ฐ ์ ์ ๋ถ์๋ช ์ผ๋ก ์ ์๋ฅผ ์ฐพ์๋ด์ด ๊ทธ ๊ฐ์ ์ด ๋ํ๋ค.
<=80: 'kill me now'
< 100 & > 80: 'i can handle this'
100 or over: 'party time!!'
๊ทธ ๊ฐ์ด 80์ดํ๋ฉด 'kill me now'
, 100๋ณด๋ค ์๊ฑฐ๋ 80 ์ด๊ณผ์ผ ๊ฒฝ์ฐ 'i can handle this'
100์ด์์ผ ๊ฒฝ์ฐ 'party time!!'
๋ฅผ returnํ๋ค.
ํด๊ฒฐ ๋ฐฉ๋ฒ
์ ์๋ฅผ ๋ํ๋ด๋ ๋ถ์๋ช ์ ๊ฐ์ฒด๋ก ๋ง๋ ๋ค.
๋ณ์๋ช ์ assessmentScore
for...in๋ฌธ์ ํตํด ๋ถ์๋ช ์ ์ ๊ทผํ ๋ค ์ด๋ฅผ assessmentScore์ key๊ฐ์ผ๋ก ์ฌ์ฉํ์ฌ ์ ์๋ฅผ ์ฐพ์๋ธ๋ค.
์ฐพ์๋ธ ์ ์๋ totalScore ๋ณ์์ ๋ํด์ค๋ค.
๋ง์ง๋ง if๋ฌธ์ ํตํด return๊ฐ์ ๋ถ๊ธฐ์ฒ๋ฆฌํ๋ค.
์ฝ๋ ๊ตฌํ
function boredom(staff) {
let totalScore = 0;
const assessmentScore = {
accounts: 1,
finance: 2,
canteen: 10,
regulation: 3,
trading: 6,
change: 6,
IS: 8,
retail: 5,
cleaning: 4,
"pissing about": 25
}
for (const key in staff) {
totalScore += assessmentScore[staff[key]];
}
if (totalScore <= 80) {
return 'kill me now';
} else if (totalScore < 100) {
return 'i can handle this';
}
return 'party time!!';
}
ํด๊ฒฐ ๋ฐฉ๋ฒ๋๋ก ์ผ๋ค.
๋นํฉ์ค๋ฌ์ ๋๊ฑด ๊ฐ์ฒด์ ํค์ ๋์ด์ฐ๊ธฐ๊ฐ ๋ค์ด๊ฐ๋ค๋ ์
"pissing about": 25
์ด ๋ถ๋ถ์ ๋ํด์๋ ์ด์ ๊ฐ์ฒด๋ฅผ ๊ณต๋ถํ์ ๋ ์๋๋ด์ฉ์ด๋ผ ์ด์ TIL๋ฅผ ์ฐธ๊ณ ํ๋ค. Object TIL
if (totalScore <= 80) {
return 'kill me now';
} else if (totalScore < 100) {
return 'i can handle this';
}
return 'party time!!';
์ด ๋ถ๋ถ์์ ๋ฐ๋ก 80์ด์๊น์ง๋ ์ฒดํฌํ ํ์๊ฐ ์์ด์ ์ฒดํฌ ํ์ง ์์๋ค.
๊ฒฐ๊ณผ ๋ถ์
random ํ ์คํธ ํต๊ณผ
CodeWars Solutions
@WompWomp's Solution
function boredom(staff){
var map = {
accounts:1,
finance:2,
canteen:10,
regulation:3,
trading: 6,
change:6,
IS:8,
retail:5,
cleaning:4,
'pissing about':25
};
var score = Object.keys(staff).reduce(
function(a,b){
return a+map[staff[b]]
},0);
return score <= 80 ? 'kill me now': score < 100 && score > 80 ? 'i can handle this' : 'party time!!';
}
Object.keys() MDN๋งํฌ Object.keys() ๋ฉ์๋๋ key๋ฅผ ๋ฐฐ์ด๋ก ๋ฐํํด์ค๋ค. ๊ทธ ๋ฐฐ์ด์ ๊ฐ์ง๊ณ Array.prototype.reduce()๋ฅผ ์ด์ฉํ๋ฉด ์์ฝ๋๋ก ํด๊ฒฐํ ์ ์๋ค. ์ด ํฉ์ reduce() ๋ฉ์๋๋ฅผ ์ด์ฉํ๋๋ก ํ์
Last updated
Was this helpful?