Skip to content

Conversation

maitreverge
Copy link

@maitreverge maitreverge commented Aug 28, 2025

Because

Despite the README.md mentionning the mandatory use of a a built-in javascript method, we can still pass this exercice with a simple solution including a bracket notation like:

const getTheTitles = function(arr) {
	let result = []
	
	result.push(arr[0]["title"]);
	result.push(arr[1]["title"]);
	return result;
};

// Do not edit below this line
module.exports = getTheTitles;

I added more tests to avoid this simple solution.

This PR

  • The file getTheTitles.spec.js and getTheTitles-solution.spec.js has been changed.
  • The following variables has been added...
  // An array dynamically generated
  const largeBooks = Array.from({ length: 1000 }, (_, i) => ({
    title: `Title${i}`,
    author: `Author${i}`,
  }));

  // And an array with different values types as book title.
  const booksWithNonStringTitles = [
    {
		title: 123,
		author: 'A',
	},
    {
		title: null,
		author: 'B',
	},
    {
		title: 'Valid',
		author: 'C',
	},
  ];
  • ...and their related test
  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',
    ]);
  });

Pull Request Requirements

  • [ x ] I have thoroughly read and understand The Odin Project Contributing Guide
  • [ x ] The title of this PR follows the ___location of change: brief description of change format, e.g. 01_helloWorld: Update test cases
  • [ x ] The Because section summarizes the reason for this PR
  • [ x ] The This PR section has a bullet point list describing the changes in this PR
  • [ ] If this PR addresses an open issue, it is linked in the Issue section
  • [ x ] If this PR includes any changes that affect the solution of an exercise, I've also updated the solution in the /solutions folder

@maitreverge maitreverge changed the title 15_getTheTitles : Added more tests to avoid 15_getTheTitles : Added more tests Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant