본문 바로가기

slice32

0209. Sort Out The Men From Boys Scenario Now that the competition gets tough it will Sort out the men from the boys . Men are the Even numbers and Boys are the odd!alt!alt Task Given an array/list [] of n integers , Separate The even numbers from the odds , or Separate the men from the boys!alt!alt Notes Return an array/list where Even numbers come first then odds Since , Men are stronger than Boys , Then Even numbers in ascen.. 2023. 2. 9.
0206. Find the nth Digit of a Number Complete the function that takes two numbers as input, num and nth and return the nth digit of num (counting from right to left). Note If num is negative, ignore its sign and treat it as a positive value If nth is not positive, return -1 Keep in mind that 42 = 00042. This means that findDigit(42, 5) would return 0 Examples(num, nth --> output) 5673, 4 --> 5 129, 2 --> 2 -2825, 3 --> 8 -456, 4 --.. 2023. 2. 7.
0205. pick a set of first elements Write a function to get the first element(s) of a sequence. Passing a parameter n (default=1) will return the first n element(s) of the sequence. If n == 0 return an empty sequence [] Examples arr = ['a', 'b', 'c', 'd', 'e'] first(arr) # --> ['a'] first(arr, 2) # --> ['a', 'b'] first(arr, 3) # --> ['a', 'b', 'c'] first(arr, 0) # --> [] Solution: def first(seq: list[str], n:int = 1) -> list[str]:.. 2023. 2. 5.
0127. Remove the time You're re-designing a blog and the blog's posts have the following format for showing the date and time a post was made: Weekday Month Day, time e.g., Friday May 2, 7pm You're running out of screen real estate, and on some pages you want to display a shorter format, Weekday Month Day that omits the time. Write a function, shortenToDate, that takes the Website date/time in its original string for.. 2023. 1. 28.
0105. Greet Me Write a method that takes one argument as name and then greets that name, capitalized and ends with an exclamation point. Example: "riley" --> "Hello Riley!" "JACK" --> "Hello Jack!" Solution: var greet = function(name) { modifiedName = name.charAt(0).toUpperCase() + name.slice(1).toLowerCase() return `Hello ${modifiedName}!` }; var greet = function(name) { return 'Hello ' + name[0].toUpperCase(.. 2023. 1. 5.
1221. Name Shuffler Write a function that returns a string in which firstname is swapped with last name. Example(Input --> Output) "john McClane" --> "McClane john" Solution: def name_shuffler(str_): return " ".join(str_.split(" ")[::-1]) 2022. 12. 21.