Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Bigger Price by Coffeemonk
import assert from "assert";
interface Stock {
name: string,
price: number,
};
function biggerPrice(limit: number, data: Stock[]): Stock[] {
return Object.values(data).sort((a,b) => { return b.price - a.price }).splice(0,limit);;
}
console.log('Example:')
console.log(biggerPrice(2, [
{"name": "bread", "price": 100},
{"name": "wine", "price": 138},
{"name": "meat", "price": 15},
{"name": "water", "price": 1}
]))
assert.deepEqual(biggerPrice(2, [
{"name": "bread", "price": 100},
{"name": "wine", "price": 138},
{"name": "meat", "price": 15},
{"name": "water", "price": 1}
]), [
{"name": "wine", "price": 138},
{"name": "bread", "price": 100}
])
assert.deepEqual(biggerPrice(1, [
{"name": "pen", "price": 5},
{"name": "whiteboard", "price": 170}
]), [{"name": "whiteboard", "price": 170}])
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
Oct. 17, 2020