/heartland-node-assessment

Node.js script that renames a given string of photos

Primary LanguageTypeScript

Photo Renaming Challenge

Mike, an avid traveler, has a collection of photos that need to be reorganized. He wants to group his photos by city, sort them by the time they were taken, and assign each photo a consecutive natural number within each city group. Additionally, he wants to rename each photo with the city name and a zero-padded number.

Problem Statement

You are given a string representing a list of photos in the following format:

"<photoname>.<extension>, <city_name>, yyyy-mm-dd hh:mm:ss"
  • <photoname> is the name of the photo.
  • <extension> is the file extension ("jpg," "png," or "jpeg").
  • <city_name> is the name of the city where the photo was taken.
  • yyyy-mm-dd hh:mm:ss is the timestamp of when the photo was taken.

Your task is to write a function that takes this input string and returns a string representing the list of new names for all photos, following Mike's renaming criteria.

Function Signature

def solution(s: str) -> str:
    pass

Example

For example, given the input string:

"photo.jpg, Krakow, 2013-09-05 14:08:15
Mike.png, London, 2015-06-20 15:13:22
myFriends.png, Krakow, 2013-09-05 14:07:13
Eiffel.jpg, Florianopolis, 2015-07-23 08:03:02
pisatower.jpg, Florianopolis, 2015-07-22 23:59:59
BOB.jpg, London, 2015-08-05 00:02:03
notredame.png, Florianopolis, 2015-09-01 12:00:00
me.jpg, Krakow, 2013-09-06 15:40:22
a.png, Krakow, 2016-02-13 13:33:50
b.jpg, Krakow, 2016-01-02 15:12:22
c.jpg, Krakow, 2016-01-02 14:34:30
d.jpg, Krakow, 2016-01-02 15:15:01
e.png, Krakow, 2016-01-02 09:49:09
f.png, Krakow, 2016-01-02 10:55:32
g.jpg, Krakow, 2016-02-29 22:13:11"

Your function should return:

Krakow02.jpg
London1.png
Krakow01.png
Florianopolis2.jpg
Florianopolis1.jpg
London2.jpg
Florianopolis3.png
Krakow03.jpg
Krakow09.png
Krakow07.jpg
Krakow06.jpg
Krakow08.jpg
Krakow04.png
Krakow05.png
Krakow10.jpg

The photos are grouped by city, sorted by timestamp, and assigned numbers as per Mike's request.

Constraints

  • M is an integer within the range (1..100).
  • Each year is an integer within the range (2000..2020).
  • Each line of the input string follows the specified format and is separated by newline characters.
  • Photo names and city names consist only of English alphabet letters (1-20 characters).
  • City names start with a capital letter followed by lowercase letters.
  • No two photos from the same location share the same date and time.
  • Each extension is "jpg," "png," or "jpeg."

In your solution, focus on correctness and efficiency.