Code Lab

Modo entrevista. Temporizador de 7 min, sin pistas y sin autocompletado

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.

Ejemplos

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

Devuelve [ '1', '3' ]

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

Devuelve []

Preguntada en T-Bank · Fuente

Cargando el 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' ]

Las pruebas ocultas se ejecutan al enviar