Created
January 11, 2026 17:55
-
-
Save davidystephenson/8350c0f52dd9ffb1bb3723035f6b5cee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const originals = { | |
| theGodfather: { | |
| budget: 7200000, | |
| director: 'Coppola', | |
| title: 'The Godfather' | |
| }, | |
| theHobbit: { | |
| author: 'Tolkien', | |
| year: 1937, | |
| title: 'The Hobbit' | |
| }, | |
| theMatrix: { | |
| budget: 63000000, | |
| director: 'Wachowskis', | |
| title: 'The Matrix' | |
| }, | |
| } | |
| const sequels = { | |
| theGodfatherPart2: { | |
| year: 1974, | |
| star: 'Al Pacino', | |
| title: 'The Godfather' | |
| }, | |
| theFellowshipOfTheRing: { | |
| protagonist: 'Frodo', | |
| price: 20, | |
| title: 'The Fellowship of the Ring' | |
| }, | |
| theMatrixReloaded: { | |
| year: 2003, | |
| star: 'Keanu Reeves', | |
| title: 'The Matrix Reloaded' | |
| }, | |
| } | |
| function analyze(collection, collectionKey, valueKey) { | |
| const data = collection[collectionKey] | |
| const value = data[valueKey] | |
| console.log('The', valueKey, 'of', data.title, 'is', value) | |
| return value | |
| } | |
| function formatString(value) { | |
| const formatted = value.toUpperCase() | |
| console.log(formatted) | |
| } | |
| function formatNumber(value) { | |
| const formatted = value.toFixed(2) | |
| console.log(`$${formatted}`) | |
| } | |
| const budget = analyze(originals, 'theGodfather', 'budget') | |
| formatNumber(budget) | |
| const author = analyze(originals, 'theHobbit', 'author') | |
| formatString(author) | |
| const director = analyze(originals, 'theMatrix', 'director') | |
| formatString(director) | |
| const star = analyze(sequels, 'theGodfatherPart2', 'star') | |
| formatString(star) | |
| const price = analyze(sequels, 'theFellowshipOfTheRing', 'price') | |
| formatNumber(price) | |
| const year = analyze(sequels, 'theMatrixReloaded', 'year') | |
| formatNumber(year) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment