Code Lab

Полки с Ремарком

ЛёгкаяMap и Set7 мин

В библиотеке два словаря. В shelves ключ это номер полки, значение массив книг на ней. В authors ключ это название книги, значение её автор.

Напиши функцию shelvesWithAuthor(shelves, authors, author). Она возвращает массив полок, на которых стоит хотя бы одна книга этого автора. Порядок полок любой.

Примеры

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

Вернёт [ '1', '3' ]

На полке 3 две книги Ремарка, но в ответе она одна.
shelvesWithAuthor({ 1: ['The Idiot'] }, { 'The Idiot': 'Dostoevsky' }, 'Remarque')

Вернёт []

Спрашивали в T-Bank · Источник

Загружаем редактор...
  1. Входные данныеshelvesWithAuthor({ '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')
    Ожидалось[ '1', '3' ]
  2. Входные данныеshelvesWithAuthor({ '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')
    Ожидалось[]
  3. Входные данныеshelvesWithAuthor({ '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')
    Ожидалось[ '1', '3' ]

Скрытые тесты запускаются по Submit.