Focus On Develop ๐ŸคŸ๐ŸคŸ

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€๋Š” ์ˆซ์ž ๋ฐฐ์—ด ๋ณธ๋ฌธ

iOS [Swift]/์•Œ๊ณ ๋ฆฌ์ฆ˜

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€๋Š” ์ˆซ์ž ๋ฐฐ์—ด

๋ˆ„๋ฆฌ๋‹ฌ์ดํ‹€ 2020. 12. 18. 11:01

<๋ฌธ์ œ>


<์ „๋žต์งœ๊ธฐ>

์ด๋ฒˆ์—๋Š” ๋˜ ํ›„ํšŒํ•˜์ง€ ๋ง๊ณ  filter๋ฅผ ์ ๊ทน ํ™œ์šฉํ•ด์•ผ๊ฒ ๋‹ค!! (๋‚œ์ด๋„ ๋งค์šฐ ์‰ฌ์šด ๋ฌธ์ œ๋ฅผ ๋ณด๋‹ˆ ๋ฐ”๋กœ ๋– ์˜ค๋ฅด๋Š”๊ตฐ ใ…‹ใ…‹ ๐Ÿ‘๐Ÿ‘) returnํ•˜๋Š” ๋ฐฐ์—ด์ด ์ •๋ ฌ๋˜์–ด์•ผ ํ•˜๋Š”๋ฐ, ์ •๋ ฌ ์‹œ์ ์€ filter๋ฅผ ํ•˜๊ธฐ ์ „/ํ›„ ๋ฌด๊ด€ํ•  ๋“ฏ ํ•˜๋‹ค.

 

 

<์ฝ”๋“œ>

func solution(_ arr:[Int], _ divisor:Int) -> [Int] {
    let divided = arr.filter { $0 % divisor == 0 }.sorted()
    return divided.count != 0 ? divided : [-1]
}

 

 

<Lesson Learned>

์•„๋งˆ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๋ฌธ์ œ ํ’€๊ธฐ ์‹œ์ž‘ํ•œ ์ดํ›„๋กœ ์ œ์ผ ๋‹จ์‹œ๊ฐ„์— ํ’€์€ ๋ฌธ์ œ์ธ๋“ฏ..!? ใ…‹ใ…‹ ๋„ˆ๋ฌด ์‰ฌ์šด๊ฑฐ ์ฐพ์•„ํ‘ธ๋Š” ๋Š๋‚Œ์ด๋ผ ์˜ค๋Š˜์€ ๋ช‡๊ฐœ ๋” ํ’€์–ด์•ผ๊ฒ ๋‹ค ๐Ÿ˜‚ ๐Ÿ˜‚

 

 

์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ ์‚ฌ์šฉ๋œ filter๊ฐ€ ๊ถ๊ธˆํ•˜๋‹ค๋ฉด?? ๐Ÿ‘‰  2020/12/15 - [iOS [Swift]/๊ธฐ์ดˆ๋ฅผ ํƒ„ํƒ„ํžˆ!] - [Swift] map, filter, reduce

 

 

์ถœ์ € : ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€๋Š” ์ˆซ์ž ๋ฐฐ์—ด

Comments