Introduction

Welcome! Today, we'll explore building a simple address book application using Go and its built-in map type. Maps in Go are versatile and allow us to manage collections of key-value pairs efficiently. This task will help you understand how to handle map operations in Go, focusing on adding, retrieving, and deleting entries. By the end of this lesson, you'll have a solid grasp of these fundamental operations and understand the practical significance of Go's map in real-world applications.

Introducing Functions to Implement

In this task, we will implement three functions to manage our address book:

  • func (ab *AddressBook) addContact(name, phoneNumber string) bool: Adds a new contact. Returns false if the contact already exists; otherwise, adds the contact and returns true. In this task, phone numbers are immutable, so overwriting an existing contact's number is not allowed.
  • func (ab *AddressBook) getContact(name string) string: Retrieves the phone number for a given name. Returns an empty string if the contact does not exist.
  • func (ab *AddressBook) deleteContact(name string) bool: Deletes a contact with the given name. Returns true if the contact exists and is deleted, otherwise.
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal