Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 44 additions & 11 deletions 15_getTheTitles/getTheTitles.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
const getTheTitles = require('./getTheTitles')

describe('getTheTitles', () => {
const books = [
{
title: 'Book',
author: 'Name'
},
{
title: 'Book2',
author: 'Name2'
}
]
const books = [
{
title: 'Book',
author: 'Name'
},
{
title: 'Book2',
author: 'Name2'
},
];

const largeBooks = Array.from({ length: 1000 }, (_, i) => ({
title: `Title${i}`,
author: `Author${i}`,
}));

const booksWithNonStringTitles = [
{
title: 123,
author: 'A',
},
{
title: null,
author: 'B',
},
{
title: 'Valid',
author: 'C',
},
];

test('gets titles', () => {
expect(getTheTitles(books)).toEqual(['Book','Book2']);
});
});
test.skip('returns empty array for empty input', () => {
expect(getTheTitles([])).toEqual([]);
});
test.skip('handles large array', () => {
expect(getTheTitles(largeBooks)).toEqual(largeBooks.map((b) => b.title));
});
test.skip('handles non-string titles', () => {
expect(getTheTitles(booksWithNonStringTitles)).toEqual([
123,
null,
'Valid',
]);
});
});
43 changes: 38 additions & 5 deletions 15_getTheTitles/solution/getTheTitles-solution.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
const getTheTitles = require('./getTheTitles-solution');
const getTheTitles = require('./getTheTitles')

describe('getTheTitles', () => {
const books = [
{
title: 'Book',
author: 'Name',
author: 'Name'
},
{
title: 'Book2',
author: 'Name2',
author: 'Name2'
},
];

const largeBooks = Array.from({ length: 1000 }, (_, i) => ({
title: `Title${i}`,
author: `Author${i}`,
}));

const booksWithNonStringTitles = [
{
title: 123,
author: 'A',
},
{
title: null,
author: 'B',
},
{
title: 'Valid',
author: 'C',
},
];

test('gets titles', () => {
expect(getTheTitles(books)).toEqual(['Book', 'Book2']);
expect(getTheTitles(books)).toEqual(['Book','Book2']);
});
test('returns empty array for empty input', () => {
expect(getTheTitles([])).toEqual([]);
});
test('handles large array', () => {
expect(getTheTitles(largeBooks)).toEqual(largeBooks.map((b) => b.title));
});
test('handles non-string titles', () => {
expect(getTheTitles(booksWithNonStringTitles)).toEqual([
123,
null,
'Valid',
]);
});
});
});