Coding 3min : Excel Puzzle #3
Description:
Introduction
In Excel, suppose you set up a column of data, data's type contains: string, integer, decimal, Date. If you set the column width is large enough, they will be displayed in their original way. If the column width is too small, there are different types of data show different results(you can try it in Excel or look at the following).
When data type is string, no matter how much is the width of a column, it will displayed all of the text.
When data type is integer or Date, If the width of the column is smaller than the width of the data, the data will be displayed as some "#".
For example, data a=12345 data b=2016-4-25
, if column width=8
, data a displayed "12345"
, data b displayed "########"
; if column width=4
, data a and data b both displayed "####"
When data type is decimal, If the width of the column is smaller than the width of the data, the data will be round to shorter decimal, until rounded to an integer.
For example, data a=1.2345, if column width=6, displayed "1.2345", if column=5, displayed "1.235", column=4, displayed "1.23",etc..
If the width of the column is smaller than the width of the data, when data rounded to an integer, the data will be displayed as some "#".
For example, data a=9.9, if column width=3, displayed "9.9"; if column=2, displayed "10"; If column=1, displayed "#".
If column width < 1, All data except string will be displayed as an empty string.
Task:
Give you two parameters: excel
(an array), like this:[1 ,"2" ,3.3 ,new Date("2004-1-1")]
(Although it is a row, but imagine it is a column), and width
(the width of column)
Return the actual display effect of excel by an array(all of elements be string format).
Some example to help you understand the rules:
solveIt([12345 ,"12345" , 1.2345, new Date("1234-5-5")],8)
=["12345","12345" ,"1.2345", "1234-5-5"]
solveIt([12345 ,"12345" , 1.2345, new Date("1234-5-5")],6)
=["12345","12345" ,"1.2345", "######"]
solveIt([12345 ,"12345" , 1.2345, new Date("1234-5-5")],5)
=["12345","12345" ,"1.235", "#####"]
solveIt([12345 ,"12345" , 1.2345, new Date("1234-5-5")],4)
=["####", "12345" ,"1.23", "####"]
solveIt([12345 ,"12345" , 1.2345, new Date("1234-5-5")],2)
=["##", "12345" ,"1", "##"]
solveIt([12345 ,"12345" , 1.2345, new Date("1234-5-5")],0.5)
=["", "12345" ,"", ""]
Please use the sort function carefully, because the original array should not be changed.
Series:
- Bug in Apple
- Father and Son
- Jumping Dutch act
- Planting Trees
- Give me the equation
- Find the murderer
- Reading a Book
- Eat watermelon
- Special factor
- Guess the Hat
- Symmetric Sort
- Are they symmetrical?
- Max Value
- Trypophobia
- Virus in Apple
- Balance Attraction
- Remove screws I
- Remove screws II
- Regular expression compression
- Collatz Array(Split or merge)
- Tidy up the room
- Waiting for a Bus
Similar Kata:
Stats:
Created | Apr 25, 2016 |
Published | Apr 25, 2016 |
Warriors Trained | 101 |
Total Skips | 1 |
Total Code Submissions | 350 |
Total Times Completed | 29 |
JavaScript Completions | 29 |
Total Stars | 1 |
% of votes with a positive feedback rating | 84% of 16 |
Total "Very Satisfied" Votes | 11 |
Total "Somewhat Satisfied" Votes | 5 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 3 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |