Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
sort slice solution in Clear category for Bigger Price by Sim0000
import assert from "assert";
function biggerPrice(limit: number, data: any[]): any[] {
return data.sort((a, b) => b.price - a.price).slice(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!");
April 24, 2020