Skip to main content

Command Palette

Search for a command to run...

JavaScript Exercises Basic#1 - Finding the smallest value among three numbers

Updated
JavaScript Exercises Basic#1 - Finding the smallest value among three numbers

Write a function to find the smallest elements among three arguments. (You cannot use sorting methods.)

Solution

   function solution(a, b, c){

                /*
                1. Declare a variable to store minimum element while comparing arguments
                2. if a is smaller than b, store value of a in the variable
                   if not, store value of b in the variable instead
                3. Either a or b is stored in the variable now 
                   Compare it to the value of c and change the value of the variable if c is smaller than min    
                */

                let min;
                if (a < b) min = a;
                else min = b;
                if (c < min) min = c;
                return min;
            }

Result

Screenshot 2022-04-12 at 19.09.44.png

M

Simple, effective and to the point. Maybe add some kind of validation for the next time? :D

R
Rey Jang4y ago

Hi thanks for your comment!! I'm fairly new to Javascript and the programming itself so I'm not sure what the validation means here๐Ÿฅบ Do you mean it'd be better if I checked whether the inputs are acceptable first or something like that?

M

Rey Jang Exactly. Just to make it more interesting and less error prone. We all have been new to everything. Keep it up!

R
Rey Jang4y ago

Marcelo Zรกrate Ah I see! I'll try to think about that next time. Thank you!!:D

More from this blog

[Kream ํด๋ก  ํ”„๋กœ์ ํŠธ] ์ƒํ’ˆ ๋”๋ณด๊ธฐ ๊ธฐ๋Šฅ

๋ชฉํ‘œ offset/limit parameter๋ฅผ ์‚ฌ์šฉํ•œ ์ƒํ’ˆ ๋”๋ณด๊ธฐ ๊ธฐ๋Šฅ ๊ตฌํ˜„ ๊ณผ์ • 1. ์ƒํ’ˆ ๋”๋ณด๊ธฐ ๊ธฐ๋Šฅ ์ƒํ’ˆ ๋ชฉ๋ก ํ•˜๋‹จ์˜ ๋”๋ณด๊ธฐ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅผ ๋•Œ๋งˆ๋‹ค ์ƒํ’ˆ์„ 8๊ฐœ์”ฉ ๋” ๋กœ๋”ฉํ•ด์˜ค๋Š” ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ์œ„ํ•ด ์˜ˆ์ „์— ๋ฐฐ์› ๋˜ query parameter์™€ offset/limit ๊ฐœ๋…์„ ํ™œ์šฉํ–ˆ๋‹ค. offset๊ณผ limit์„ ์„ค์ •ํ•ด๋‘๋ฉด ๋ฐ์ดํ„ฐ ์š”์ฒญ ํ›„ ๋ฐ›์•„์˜จ ๊ฒฐ๊ณผ๊ฐ’์— ์ˆœ์„œ๋ฅผ ๋ถ€์—ฌํ•ด์„œ offset๋ถ€ํ„ฐ limit๊นŒ์ง€์˜ ๋ฐ์ดํ„ฐ๋งŒ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ๋„๋ก ํŽ˜์ด์ง• ์ฒ˜๋ฆฌ...

Jul 22, 2022

[Kream ํด๋ก  ํ”„๋กœ์ ํŠธ] ์ƒํ’ˆ ๊ฒ€์ƒ‰ & ์ •๋ ฌ ๊ธฐ๋Šฅ

๋ชฉํ‘œ ์ƒํ’ˆ์˜ ๊ฒ€์ƒ‰๊ณผ ์˜ต์…˜๋ณ„ ์ •๋ ฌ์ด ๊ฐ€๋Šฅํ•œ ์ƒํ’ˆ ๋ชฉ๋ก ํŽ˜์ด์ง€ ๊ตฌํ˜„ ๊ณผ์ • 1. ์ƒํ’ˆ ๋ชฉ๋ก(๋ฉ”์ธ) ํŽ˜์ด์ง€ UI 1) Kream์ด ์ƒํ’ˆ ๊ฑฐ๋ž˜ ์‚ฌ์ดํŠธ์ด๋‹ค๋ณด๋‹ˆ ๊ฐ ์ƒํ’ˆ๋งˆ๋‹ค ๋™์ผํ•˜๊ฒŒ ๋ฐ˜๋ณต๋˜๋Š” ์–‘์‹๋“ค์ด ๋งŽ์•˜๋Š”๋ฐ, ์ด ๋ถ€๋ถ„๋“ค์„ ์ „๋ถ€ ์ปดํฌ๋„ŒํŠธ๋กœ ๋งŒ๋“ค๊ณ  ์žฌ์‚ฌ์šฉํ•จ์œผ๋กœ์จ ์ฝ”๋“œ์˜ ๊ธธ์ด๋ฅผ ๋งŽ์ด ์ค„์ผ ์ˆ˜ ์žˆ์—ˆ๋‹ค. ํŠนํžˆ 2์ฐจ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” styled components๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ ๊ฐ ํŽ˜์ด์ง€๋งˆ๋‹ค jsํŒŒ์ผ์˜ ์ฝ”๋“œ ์–‘์ด ๋‘๋ฐฐ๋กœ ๋งŽ์•„์ง€๋Š” ๋ฐ”๋žŒ์— ํ•œ๋ฒˆ ์ž‘์„ฑํ•˜๊ณ ๋‚˜๋ฉด ์•Œ์•„๋ณด๊ธฐ๊ฐ€...

Jul 22, 2022

[Kream ํด๋ก  ํ”„๋กœ์ ํŠธ] ํšŒ๊ณ 

ํ”„๋กœ์ ํŠธ๋ช… 'CREAM' ํ•œ์ •ํŒ ์ƒํ’ˆ ๊ฑฐ๋ž˜ ํ”Œ๋žซํผ 'KREAM'์˜ ๊ธฐํš, ๋””์ž์ธ ํด๋ก  2์ฃผ๊ฐ„ Front-end/Back-end ๊ฐœ๋ฐœ ์ง„ํ–‰ ์ œ์ž‘ ๊ธฐ๊ฐ„ / ์ธ์› 2022๋…„ 6์›” 6์ผ - 2022๋…„ 6์›” 17์ผ Front-end 4๋ช… & Back-end 1๋ช… ์ ์šฉ ๊ธฐ์ˆ  / ํ˜‘์—… ๋„๊ตฌ JSX, Styled-Components, React Notion, Github, Trello, Slack ํ”„๋กœ์ ํŠธ ๋‹ฌ์„ฑ ๋ชฉํ‘œ 1์ฐจ ํ”„๋กœ์ ํŠธ์—์„œ ๊ฐ์ž ํ•ด๋ณด์ง€ ...

Jul 21, 2022

[Lululemon ํด๋ก  ํ”„๋กœ์ ํŠธ] ์žฅ๋ฐ”๊ตฌ๋‹ˆ ํŽ˜์ด์ง€

๋ชฉํ‘œ ์ƒํ’ˆ ์ถ”๊ฐ€ / ์‚ญ์ œ / ์ˆ˜๋Ÿ‰ ๋ณ€๊ฒฝ์ด ๊ฐ€๋Šฅํ•œ ์žฅ๋ฐ”๊ตฌ๋‹ˆ ํŽ˜์ด์ง€ ๊ตฌํ˜„ ๊ณผ์ • 1. ์ƒํ’ˆ ๋ฐ์ดํ„ฐ ๋ฐ›์•„์˜ค๊ธฐ 1) ์‚ฌ์šฉ์ž๊ฐ€ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ๋„ฃ์€ ์ƒํ’ˆ๋“ค์˜ ๋ชฉ๋ก์„ ๋ Œ๋”๋งํ•˜๊ธฐ์œ„ํ•ด fetch ํ•จ์ˆ˜๋กœ ์„œ๋ฒ„์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์˜จ ํ›„ 'itemList' ๋ณ€์ˆ˜์— ์ €์žฅํ•ด๋‘์—ˆ๋‹ค . 2) ์‚ฌ์šฉ์ž๋ฅผ ์‹๋ณ„ํ•œ ๋‹ค์Œ ๊ทธ์— ๋งž๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์™€์•ผํ•˜๊ธฐ๋•Œ๋ฌธ์— request header์— ๋กœ๊ทธ์ธ์‹œ ๋ฐœ๊ธ‰ํ–ˆ๋˜ ํ† ํฐ ์ธ๊ฐ€ ๊ณผ์ •์„ ์ถ”๊ฐ€ํ–ˆ๋‹ค. ์ฝ”๋“œ๐Ÿ”ป const Bag = () => { co...

Jun 11, 2022

[Lululemon ํด๋ก  ํ”„๋กœ์ ํŠธ] ๋กœ๊ทธ์ธ/ํšŒ์›๊ฐ€์ž… ํŽ˜์ด์ง€

๋ชฉํ‘œ JWT ์ธ์ฆ๋ฐฉ์‹์„ ํ™œ์šฉํ•œ ๋กœ๊ทธ์ธ/ํšŒ์›๊ฐ€์ž… ํŽ˜์ด์ง€ ๊ตฌํ˜„ ๊ณผ์ • 1. ๋กœ๊ทธ์ธ/ํšŒ์›๊ฐ€์ž… ํŽ˜์ด์ง€ UI 1) lululemon์˜ ์‚ฌ์ดํŠธ๋Š” ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€์—์„œ ํšŒ์›๊ฐ€์ž… ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ์–‘์‹์ด ์Šฌ๋ผ์ด๋“œ๋กœ ์˜ฌ๋ผ์™€ ํ•œ ํŽ˜์ด์ง€์—์„œ ๋กœ๊ทธ์ธ๊ณผ ํšŒ์›๊ฐ€์ž…์„ ๋ชจ๋‘ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ์‹์œผ๋กœ ๋˜์–ด ์žˆ์—ˆ๋‹ค. ์ด๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ๋กœ๊ทธ์ธ ์–‘์‹๊ณผ ํšŒ์›๊ฐ€์ž… ์–‘์‹์„ ๊ฐ๊ฐ ์ปดํฌ๋„ŒํŠธ๋กœ ๋งŒ๋“  ๋’ค 'modal' ๋ณ€์ˆ˜์˜ ์ƒํƒœ๊ฐ’์ด true์ธ์ง€ false์ธ์ง€์— ๋”ฐ๋ผ ์ ์ ˆํ•œ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ Œ๋”๋ง๋  ์ˆ˜ ...

Jun 11, 2022

Rey's Blog

49 posts