docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a product comparison tool that efficiently maintains a sorted catalog and helps find the correct insertion position for new products based on their prices.
You need to implement a product catalog system that:
Products are represented as objects with the following structure:
{
name: string,
category: string,
price: number
}Implement a function findInsertionIndex(catalog, newProduct) that:
catalog) sorted by price in ascending ordernewProduct)/**
* Finds the insertion index for a new product in a sorted catalog
* @param {Array<Object>} catalog - Array of products sorted by price
* @param {Object} newProduct - The product to insert
* @returns {number} The index where the product should be inserted
*/
function findInsertionIndex(catalog, newProduct) {
// Implementation here
}
module.exports = { findInsertionIndex };[] and a product with price 50, returns index 0 @test[10, 20, 30, 40] and a new product with price 25, returns index 2 @test[10, 20, 30] and a new product with price 5, returns index 0 @test[10, 20, 30] and a new product with price 35, returns index 3 @test[15, 25, 25, 40] and a new product with price 25, returns index 1 (first position where 25 can be inserted) @testProvides utility functions for working with arrays and objects.