Skip to content

Conversation

ryong9rrr
Copy link
Contributor

@ryong9rrr ryong9rrr commented Oct 18, 2022 โ€ข

์ƒˆ๋กญ๊ฒŒ ์ถ”๊ฐ€๋œ ๋ฌธ์ œ ํ’€์ด

4 / ๋ฌด์ง€์˜ ๋จน๋ฐฉ ๋ผ์ด๋ธŒ 9e5c6fb

4 / ๊ฐ€์‚ฌ ๊ฒ€์ƒ‰ 7350eb5

๊ธฐ์กด ํ’€์ด์— ์ถ”๊ฐ€ํ•œ ํ’€์ด

๊ด€๋ จ ์ด์Šˆ

Copy link
Owner

@codeisneverodd codeisneverodd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ธฐ์—ฌํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!! ์ฝ”๋“œ ์Šคํƒ€์ผ๋„ ํ™•์‹คํ•˜์‹œ๊ณ , ๊น”๋”ํ•˜๊ฒŒ ์ž‘์„ฑ๋˜์–ด์žˆ์–ด์„œ ํฌ๊ฒŒ ์ฝ”๋ฉ˜ํŠธ ํ• ๊ฒŒ ์—†์—ˆ์Šต๋‹ˆ๋‹ค!
ํ˜•์‹๋„ ์ž˜ ๋งž์ถฐ์ฃผ์…”์„œ ๋ฐ”๋กœ approve ํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ˜„

๊ฐ™์ด ํŒ€ ํ•ด๋ณด๊ณ  ์‹ถ์—ˆ๋Š”๋ฐ ์•„์‰ฝ๋„ค์š”!! ์—ฐ๋ฝ ์ฑ„๋„์ด ์—†์–ด์„œ ํ˜น์‹œ ๋ณด์‹œ๋ฉด codeisneverodd@gmail.com๋กœ ๋ฉ”์ผ ํ•˜๋‚˜๋งŒ ๋ณด๋‚ด์ฃผ์‹ค ์ˆ˜ ์žˆ์„๊นŒ์š”?! @ryong9rrr

}

// stack์œผ๋กœ ํ’€๊ธฐ
const stack = food_times.map((time, i) => [time, i + 1]).sort((a, b) => b[0] - a[0])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort ๊ตฌ๋ฌธ ๋ฐ”๋กœ ์•ž์— 0๋ฒˆ ์ธ๋ฑ์Šค๊ฐ€ time์„ ์˜๋ฏธํ•˜๋Š” ๊ฒƒ์ด ๋ช…์‹œ๊ฐ€ ๋˜์–ด์žˆ์–ด์„œ ํฌ๊ฒŒ ํ•„์š”ํ•˜์ง„ ์•Š์ง€๋งŒ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ‘œํ˜„๋„ ๊ณ ๋ คํ•ด๋ณด์„ธ์š”! ์Šคํƒ€์ผ ์ฐจ์ด์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค ๐Ÿ˜„

const stack = food_times.map((time, i) => [time, i + 1]).sort(([timeA], [timeB]) => timeB - timeA);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜๋ฏธ๊ฐ€ ๋” ๋ช…ํ™•ํ•ด์ง€๋Š” ๊ฒƒ ๊ฐ™๋„ค์š” ๐Ÿ‘๐Ÿ‘


let prev = 0
while (stack.length > 0 && k >= 0) {
const time = stack[stack.length - 1][0]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ตฌ์กฐ๋ถ„ํ•ด ํ• ๋‹น ์Šคํƒ€์ผ๋„ ๊ณ ๋ คํ•ด๋ณด์„ธ์š”! ์ €๋Š” ์ด ์Šคํƒ€์ผ์ด ์กฐ๊ธˆ ๋” ์˜๋ฏธ๋ฅผ ํŒŒ์•…ํ•˜๊ธฐ ์‰ฝ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋Š”๋ฐ ์–ด๋–ป๊ฒŒ ์ƒ๊ฐํ•˜์‹œ๋‚˜์š”?? @ryong9rrr ๋‹˜ ์˜๊ฒฌ์ด ๊ถ๊ธˆํ•˜๋„ค์š”!

const [time] = stack[stack.length - 1];

Copy link
Contributor Author

@ryong9rrr ryong9rrr Oct 20, 2022 โ€ข

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์‚ฌ์†Œํ•œ ๋ถ€๋ถ„์ธ๋ฐ ํ›จ์”ฌ ๋‚˜์•„์ง€๋„ค์š”!!! ๐Ÿ‘๐Ÿ‘๐Ÿ‘

Comment on lines +25 to +26
const result = stack
.reverse()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverse ๋ฉ”์„œ๋“œ๋Š” ์›๋ณธ ๊ฐ์ฒด๋ฅผ ๋ณ€ํ™”์‹œํ‚ค๋Š” side effect๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค! ๋”ฐ๋ผ์„œ ์˜๋„ํ•œ ๊ฒƒ์ด ์•„๋‹ˆ๋ผ๋ฉด ๋ณต์‚ฌ๋ณธ์„ ์ƒ์„ฑํ•˜์—ฌ reverse๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค ๐Ÿ‘

const result = [...stack] .reverse()

sort๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์›๋ณธ ๊ฐ์ฒด๋ฅผ ๋ณ€ํ™”์‹œํ‚ค์ง€๋งŒ, 11๋ฒˆ ๋ผ์ธ์—์„œ๋Š” map์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‚˜์˜จ ๋ณต์‚ฌ๋ณธ์— sort๋ฅผ ํ•˜์˜€๊ธฐ ๋•Œ๋ฌธ์— food_times ์›๋ณธ ๋ฐฐ์—ด์—๋Š” ์˜ํ–ฅ์„ ๋ผ์น˜์ง€ ์•Š์•˜์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์›๋ž˜ ์ด ์ฝ”๋“œ๊ฐ€ ํŒŒ์ด์ฌ์˜ "ํ"๋ฅผ ์‚ฌ์šฉํ•œ ํ’€์ด์˜€๋Š”๋ฐ, ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ์ž‘์„ฑํ•˜๋ฉด์„œ ํ๋ฅผ ์Šคํƒ์œผ๋กœ ์ „ํ™˜ํ•ด์„œ ํ’€์ดํ•˜๊ฒŒ ๋์–ด์š”. ๊ทธ๋Ÿฌ๋‹ค๋ณด๋‹ˆ ์˜๋„์ ์œผ๋กœ ์Šคํƒ์„ ๋’ค์ง‘์—ˆ์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž

๋งŒ์•ฝ ์Šคํƒ ๋ฐ์ดํ„ฐ๋ฅผ ์œ ์ง€์‹œ์ผœ์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ๋ผ๋ฉด ๋ง์”€๋Œ€๋กœ ๋ณต์‚ฌ๋ณธ์„ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์ด ๋งž์Šต๋‹ˆ๋‹ค!!


const result = stack
.reverse()
.map((item) => item[1])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

item์˜ 1๋ฒˆ ์ธ๋ฑ์Šค๊ฐ€ ์˜๋ฏธํ•˜๋Š” ๊ฒƒ์„ ์œ„์—์„œ๋ถ€ํ„ฐ ๊ธฐ์–ตํ•˜๋ฉฐ ์˜ค๊ธฐ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์œผ๋‹ˆ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ‘œํ˜„๋„ ๊ณ ๋ คํ•ด๋ณด์„ธ์š”!

.map(([_, order]) => order)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜๋ฏธ๊ฐ€ ํ›จ์”ฌ ๋ช…ํ™•ํ•ด์ง‘๋‹ˆ๋‹ค ใ…Žใ…Ž ๋ฐ”์˜์‹คํ…๋ฐ ๋ฆฌ๋ทฐ ๊ฐ์‚ฌ๋“œ๋ ค์š” ๐Ÿฅฐ

@ryong9rrr
Copy link
Contributor Author

ryong9rrr commented Oct 20, 2022 โ€ข

@codeisneverodd <๋ฌด์ง€์˜ ๋จน๋ฐฉ ๋ผ์ด๋ธŒ> ์ฝ”๋“œ๋ฆฌ๋ทฐ ๋ฐ˜์˜ํ•ด์„œ ์ปค๋ฐ‹ ์˜ฌ๋ ธ์Šต๋‹ˆ๋‹ค! ์‹œ๊ฐ„๋˜์‹ค ๋•Œ ๋ฉ”์ผ๋„ ํ™•์ธํ•ด์ฃผ์„ธ์š” ๐Ÿ˜†

@codeisneverodd codeisneverodd merged commit c854aee into codeisneverodd:main Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants