Skip to main content

Hello NQE Enthusiasts,

 

Here is another Koan challenge. The task is to take a list of years and calculate the centuries


Input:
>1776, 2001, 1643, 1969];


Result
>{“Year”: 1776, “Century”: 18}...]


Hints:

Use string conversions like toString 

Create a toNumber function


Try not to look at the replies until you have tried the challenge yourself.

This was fun 😁
 

foreach year in r1776, 2001, 1643, 1969]
let firstTwoDigits = year / 100
let century = firstTwoDigits + 1
select { year, century }

 


What sort of programming magic would you use to make the centuries ordinal numbers?

myCenturyFunction(year) : Number = year/100 +1;

//How would you present the century as an ordinal number?

years = [776, 2001, 1643, 1969];

foreach year in years
select { Year: toString(year), Century: myCenturyFunction(year) }

 


Reply