Normalise a MAC address

A free easy coding practice problem from networking. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.

Difficulty
Easy
Type
Function
Topic
Networking
Languages
JavaScript, TypeScript or Python

Problem

Network tools print MAC addresses in different styles. Accept exactly these four forms (hex digits in any case):
- six 2-digit groups separated by colons: AA:BB:CC:DD:EE:FF
- six 2-digit groups separated by dashes: aa-bb-cc-dd-ee-ff
- three 4-digit groups separated by dots (Cisco): aabb.ccdd.eeff
- twelve hex digits with no separator: AABBCCDDEEFF

Return the address in canonical form — lowercase, six 2-digit groups joined by colons — or null (Python: None) if s matches none of the forms (mixed separators, wrong group sizes, non-hex characters, surrounding spaces…).

Function signature

// JavaScript
function normalizeMac(s)

// TypeScript
function normalizeMac(s: any): any

// Python
def normalize_mac(s):

Examples

  1. normalizeMac("AA-BB-CC-DD-EE-FF") → "aa:bb:cc:dd:ee:ff"
  2. normalizeMac("0011.2233.4455") → "00:11:22:33:44:55"
  3. normalizeMac("00:11:22:33:44") → null

How checking works

Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.

More practice problems

Next steps