본문 바로가기

DART23

1119. Return Negative In this simple assignment you are given a number and have to make it negative. But maybe the number is already negative? Examples makeNegative(1); // return -1 makeNegative(-5); // return -5 makeNegative(0); // return 0 makeNegative(0.12); // return -0.12 Notes The number can be negative already, in which case no change is required. Zero (0) is not checked for any specific sign. Negative zeros m.. 2022. 11. 19.
1118. Function 1 - hello world Description: Make a simple function called greet that returns the most-famous "hello world!". Style Points Sure, this is about as easy as it gets. But how clever can you be to create the most creative hello world you can think of? What is a "hello world" solution you would want to show your friends? Solution: String greet() => 'hello world!'; 2022. 11. 18.
1117. Reverse List Order In this kata you will create a function that takes in a list and returns a list with the reverse order. Examples (Input -> Output) * [1, 2, 3, 4] -> [4, 3, 2, 1] * [9, 2, 0, 7] -> [7, 0, 2, 9] Solution: List reverseList(List list) { return list.reversed.toList(); } List reverseList(List list)=>[...list.reversed]; List reverseList(List list) => List.from(list.reversed); 2022. 11. 17.
1116. Convert boolean values to strings 'Yes' or 'No'. Complete the method that takes a boolean value and return a "Yes" string for true, or a "No" string for false. Solution: String bool_to_word(bool boolean) { String result = "No"; if (boolean == true) { result = "Yes"; } return result; } // or String bool_to_word(bool boolean) => boolean ? "Yes" : "No"; 2022. 11. 17.
1115. Reversed Strings Complete the solution so that it reverses the string passed into it. 'world' => 'dlrow' 'word' => 'drow' Solution: String solution(str) { return str.split('').reversed.join(''); } 2022. 11. 15.