Americans have a unique way of numbering floors in buildings, where the first floor is considered the ground floor and there is no 13th floor due to superstition. A function is needed to convert American floor numbers to European floor numbers. In the European system, the first floor is replaced by the ground floor, and the 13th floor is removed, causing the numbers above it to shift down. Floors above 13 move down by two because of the two omitted numbers below them. Basement levels, which are negative numbers, remain the same in both systems. The function should return 0 for an input of 1, 0 for an input of 0, 4 for an input of 5, 13 for an input of 15, and -3 for an input of -3. Two possible solutions are provided, both of which use conditional statements to determine the correct output. The first solution uses if-else statements, while the second solution uses a ternary operator. The problem is considered an easy challenge with a rank of 8kyu on CodeWars. The solutions are straightforward and simply return different numbers based on the input conditions.
dev.to
dev.to
Create attached notes ...