Code Lab

Modo entrevista. Cronômetro de 7 min, sem dicas e sem autocompletar

Shelves with Remarque

FácilMap and Set7 min

A library has two dictionaries. In shelves the key is a shelf number and the value is an array of books on it. In authors the key is a book title and the value is its author.

Write a function shelvesWithAuthor(shelves, authors, author). It returns an array of the shelves that have at least one book by that author. Any order of shelves is fine.

Exemplos

shelvesWithAuthor({ 1: ['Three Comrades'], 2: ['The Idiot'], 3: ['Arch of Triumph', 'Three Comrades'] }, { 'Three Comrades': 'Remarque', 'The Idiot': 'Dostoevsky', 'Arch of Triumph': 'Remarque' }, 'Remarque')

Retorna [ '1', '3' ]

Shelf 3 has two Remarque books, but it is in the answer once.
shelvesWithAuthor({ 1: ['The Idiot'] }, { 'The Idiot': 'Dostoevsky' }, 'Remarque')

Retorna []

Cobrada em T-Bank · Fonte

Carregando o editor...
  1. EntradashelvesWithAuthor({ '1': [ 'Three Comrades' ], '2': [ 'The Idiot' ], '3': [ 'Arch of Triumph', 'Three Comrades' ] }, { 'Three Comrades': 'Remarque', 'Arch of Triumph': 'Remarque', 'All Quiet on the Western Front': 'Remarque', 'The Idiot': 'Dostoevsky', 'The Master and Margarita': 'Bulgakov', 'Heart of a Dog': 'Bulgakov' }, 'Remarque')
    Esperado[ '1', '3' ]
  2. EntradashelvesWithAuthor({ '1': [ 'The Idiot' ] }, { 'Three Comrades': 'Remarque', 'Arch of Triumph': 'Remarque', 'All Quiet on the Western Front': 'Remarque', 'The Idiot': 'Dostoevsky', 'The Master and Margarita': 'Bulgakov', 'Heart of a Dog': 'Bulgakov' }, 'Remarque')
    Esperado[]
  3. EntradashelvesWithAuthor({ '1': [ 'Heart of a Dog', 'The Idiot' ], '2': [ 'Three Comrades' ], '3': [ 'The Master and Margarita' ] }, { 'Three Comrades': 'Remarque', 'Arch of Triumph': 'Remarque', 'All Quiet on the Western Front': 'Remarque', 'The Idiot': 'Dostoevsky', 'The Master and Margarita': 'Bulgakov', 'Heart of a Dog': 'Bulgakov' }, 'Bulgakov')
    Esperado[ '1', '3' ]

Os testes ocultos rodam no envio