๐Ÿ“
til
  • TIL(Today I Learned)
  • javascript
    • value-number-string-boolean-null-undefined
    • primitive-reference
    • Hoisting
    • Prototypes in Javascript
    • this
    • prototype
    • ์ฝœ๋ฐฑํ•จ์ˆ˜ (Callback function)
    • ํ•จ์ˆ˜์˜ ํ˜ธ์ถœ
    • ์ž๋ฃŒ๊ตฌ์กฐ new keyword
    • closure
    • Promise
    • event-loop
    • array-object
    • ๊ฐ์ฒด
    • Arguments
    • higher order function
    • operators-function-control-flow
    • ๊ฐ์ฒด ์ƒ์„ฑ ํŒจํ„ด 3๊ฐ€์ง€
    • Javascript scopes
    • Functional Programming
    • Design Patterns
    • ๋ฐ์ดํ„ฐ ํƒ€์ž…
    • Object ๊ฐ์ฒด
    • ํ‘œ์ค€ ๋‚ด์žฅ ๊ฐ์ฒด์˜ ํ™•์žฅ
    • ์ฐธ์กฐ
    • ํ•จ์ˆ˜
    • ์ƒ์†(Inheritance)
    • this - 'this'๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ '์–ด๋–ป๊ฒŒ' ์‹คํ–‰ํ•˜๋А๋ƒ์— ๋”ฐ๋ฅธ 4๊ฐ€์ง€ this ์ •์˜
    • ์ „์—ญ๊ฐ์ฒด(Global object)
    • ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ
    • The 'new' keyword - Object Creation in JavaScript
  • javascript-api
    • Number
      • Number.MAX_VALUE
      • Number.isInteger
      • Number.NEGATIVE_INFINITY
      • Number.isNaN()
      • Number.POSITIVE_INFINITY
      • Number.parseFloat
      • Number.EPSILON
      • number.toExponential
      • Number.MAX_SAFE_INTEGER
      • Number1 - ์ž์—ฐ์ˆ˜, ์ •์ˆ˜, 10์ง„์ˆ˜, 2์ง„์ˆ˜, ๋ถ€๋™์†Œ์ˆ˜์ , ์‹ค์ˆ˜
      • Number.isSafeInteger()
      • Number.MIN_VALUE
      • Number.parseInt
      • Number.NaN
      • Number.isFinite()
      • Number.MIN_SAFE_INTEGER
      • toFixed
    • string.split
    • String.fromCodePoint
    • string.trimEnd
    • string.padStart
    • string.@@iterator
    • String.fromCharCode
    • string.toUpperCase
    • string.codePointAt
    • string.toLowerCase()
    • string.toString
    • string.includes
    • string.replace()
    • string.charAt
    • String.lastIndexOf
    • string.slice
    • string.search
    • string.padEnd
    • string.substring
    • string.length
    • string.trim
    • string.localeCompare
    • String.indexOf
    • string.endsWith
    • string.valueOf
    • String.raw
    • string.matchAll()
    • string.repeat
    • string.match
    • String.prototype
    • string.startsWith
    • string.charCodeAt
    • string.trimStart
    • string.concat
    • string.toLocaleUpperCase()
    • string.toLocaleLowerCase
    • String
  • learn-node
    • debugger
    • Tip
  • schema-design
    • Database Schema Design
    • Database Schema Design
  • react
    • LifeCycle
    • redux
    • Context API
    • ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์™€ ํด๋ž˜์Šค, ์–ด๋–ค ์ฐจ์ด๊ฐ€ ์กด์žฌํ• ๊นŒ?
    • Hooks๊ณผ useEffect ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ
    • Route
    • async wait ์‚ฌ์šฉํ•˜๊ธฐ
    • Hooks API Reference
    • context
    • npm uninstall ํ•˜๋Š”๋ฒ•
    • test ๋งŒ๋“ค๊ธฐ
  • tip
    • ํด๋ฆฐ์ฝ”๋“œ
    • BxSlider๋กœ ํ…์ŠคํŠธ ํ๋ฅด๋Š” ํšจ๊ณผ ๋งŒ๋“ค๊ธฐ
  • javascript30
    • Event Capture, Propagation, Bubbling and Once
    • Object and Arrays - Reference VS Copy
  • typescript
    • ์šฐ์•„ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ 2๋ถ€
    • The Basic Cheatsheet
    • TypeScript
    • Type Guards and Differnetiating Types
    • ์šฐ์•„ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ
    • Generics
  • git-from-the-hell
    • git
    • init-status-add-commit-log-stage-repository
    • log-diff
    • ๋จธ์ง€ ํ›„ branch ์‚ญ์ œํ•˜๊ธฐ
    • ์ง€์˜ฅ์—์„œ ์˜จ Git
    • reset-revert
    • develop branch ๋ฅผ pull ํ•˜๊ณ  ์‹ถ์„๋•Œ
  • conference-and-seminar
    • ๋ชจ๋˜ ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœํ™˜๊ฒฝ์˜ ์ดํ•ด
  • fire-base
    • Firebase .gitignore
  • vanillacoding
    • Data Structures
    • Sorting Algorithms - part 1
    • Promise
    • class
    • 04.quiz
    • 07.event-loop
    • Design Patterns
    • OOP (Object Oriented Programming)
  • etc
    • ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ฝ”๋“œ๋ฆฌ๋ทฐ
    • ์Šค์Šค๋กœ ๊ณต๋ถ€ํ•˜๋Š” ๋ฒ•
    • ๋ฐ”๋‹๋ผ์ฝ”๋”ฉ ์ˆ˜๊ฐ• ํ›„๊ธฐ
    • async ๊ณผ์ œ ํ›„๊ธฐ - ๋น„๋™๊ธฐ, ๋™๊ธฐ, ํด๋กœ์ €, ๋ฐฐ์—ด๊ณผ ๊ฐ์ฒด
    • ์œ ์šฉํ•œ ์‚ฌ์ดํŠธ
  • algorithm
    • The Supermarket Queue
    • Find the odd int
    • The Office III - Broken Photocopier
    • Directions Reduction
    • The Office II - Boredom Score
    • Divisible Sum Pairs
    • Codewars ์ด์šฉ์ž ์†”๋ฃจ์…˜ ๋ชจ์Œ
    • Shortest Word
    • find key
    • Two Sum
    • Simple Pig Latin
  • Book
    • the essence of object-orientation
      • ํƒ€์ž…๊ณผ ์ถ”์ƒํ™”
      • ๊ฐ์ฒด ์ง€๋„
      • ์ด์ƒํ•œ ๋‚˜๋ผ์˜ ๊ฐ์ฒด
      • ์ถ”์ƒํ™” ๊ธฐ๋ฒ•
      • 05. ์ฑ…์ž„๊ณผ ๋ฉ”์‹œ์ง€
      • 07.ํ•จ๊ป˜ ๋ชจ์œผ๊ธฐ
      • 04. ์—ญํ• , ์ฑ…์ž„, ํ˜‘๋ ฅ
      • ํ˜‘๋ ฅํ•˜๋Š” ๊ฐ์ฒด๋“ค์˜ ๊ณต๋™์ฒด
  • ecma-script2015
    • Object Literal Upgrades
    • default-parameter-template-literals-arrow-functions
    • spread-operator-rest-param
    • let-const-rest-parameter-spread-operator-destructuring
  • http
    • ์›น ๋ธŒ๋ผ์šฐ์ €์— URL์„ ์ž…๋ ฅํ–ˆ์„ ๋•Œ ์–ด๋–ป๊ฒŒ ์›น ํŽ˜์ด์ง€๊ฐ€ ๋ณด์—ฌ์งˆ๊นŒ?
  • jest
    • toThrow(error?)
  • data-structures
    • Data Structures
  • express
    • express generator
    • CORS
  • css-flexible-box-layout
    • flex ํ•ด๋ฒ„๋ ธ์ง€ ๋ญ์•ผ
  • git
    • Git
  • mongodb
    • MongoDB
  • markdown
    • use-markdown
  • cmder
    • cmd ๋ช…๋ น์–ด ๋ชจ์Œ
  • debug
    • trackClicksEx function error
  • npm
    • NPM TOKEN ์„ค์ •ํ•˜๊ธฐ
  • storybook
    • Storybook
  • sort
    • Sorting Algorithms - part 1
  • javascript-koans
    • Javascript Koans ์˜ค๋‹ต๋…ธํŠธ
  • rxjs
    • Rx.js
  • dom-elements
    • HTML Element
  • redux-toolkit
    • Redux Toolkit
  • github-actions
    • GitHub Actions
  • redux-middleware
    • redux middleware
  • rest
    • rest
  • css-rendering
    • ์ฝ”๋“œ ์Šคํ”ผ์ธ  - CSS Rendering 1ํšŒ์ฐจ 2/2
    • ์ฝ”๋“œ ์Šคํ”ผ์ธ  - CSS Rendering 1ํšŒ์ฐจ 1/2
  • you-dont-know-js
    • ํƒ€์ž…
  • server
    • # shutdown local server
  • semantic-versioning
    • Semantic Versioning 2.0.0
Powered by GitBook
On this page
  • ๋ฌธ์ œ
  • ๋ฌธ์ œ ์ดํ•ด
  • ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•
  • ์ฝ”๋“œ ๊ตฌํ˜„
  • ๊ฒฐ๊ณผ ๋ถ„์„
  • CodeWars Solutions

Was this helpful?

  1. algorithm

The Office II - Boredom Score

PreviousDirections ReductionNextDivisible Sum Pairs

Last updated 5 years ago

Was this helpful?

์‹œ๋ฆฌ์ฆˆ๊ฐ€ ์žฌ๋ฐŒ๋‹ค. 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
if (totalScore <= 80) {
    return 'kill me now';
} else if (totalScore < 100) {
    return 'i can handle this';
}
return 'party time!!';

์ด ๋ถ€๋ถ„์—์„œ ๋”ฐ๋กœ 80์ด์ƒ๊นŒ์ง€๋Š” ์ฒดํฌํ•  ํ•„์š”๊ฐ€ ์—†์–ด์„œ ์ฒดํฌ ํ•˜์ง€ ์•Š์•˜๋‹ค.

๊ฒฐ๊ณผ ๋ถ„์„

random ํ…Œ์ŠคํŠธ ํ†ต๊ณผ

CodeWars Solutions

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!!';
}

์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ๋Š” ์ด์ „ ๊ฐ์ฒด๋ฅผ ๊ณต๋ถ€ํ–ˆ์„ ๋•Œ ์žˆ๋˜๋‚ด์šฉ์ด๋ผ ์ด์ „ TIL๋ฅผ ์ฐธ๊ณ ํ–ˆ๋‹ค.

@'s Solution

Object.keys() ๋ฉ”์„œ๋“œ๋Š” key๋ฅผ ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•ด์ค€๋‹ค. ๊ทธ ๋ฐฐ์—ด์„ ๊ฐ€์ง€๊ณ  Array.prototype.reduce()๋ฅผ ์ด์šฉํ•˜๋ฉด ์ˆ์ฝ”๋“œ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด ํ•ฉ์€ reduce() ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•˜๋„๋ก ํ•˜์ž

codewars ๋งํฌ
Object TIL
WompWomp
Object.keys() MDN๋งํฌ
jsํŒŒ์ผ ๋ฐ”๋กœ๊ฐ€๊ธฐ