function splitByTitle(movies: Array): { [s: string]: Movie[]; } { const result = movies.reduce((r, a) => { var letter = a.title[0].toUpperCase(); if (!isNaN(parseInt(letter))) letter = "#"; r[letter] = r[letter] || []; r[letter].push(a); return r; }, Object.create(null)); return result; } function splitByYear(movies: Array): { [s: string]: Movie[]; } { const result = movies.reduce((r, a) => { const year = new Date(a.released).getFullYear(); r[year] = r[year] || []; r[year].push(a); return r; }, Object.create(null)); return result; } export { splitByTitle, splitByYear };