function getGemsOfColor(color, gems) { return gems.filter(gem => gem.colors.includes(color)).map(it => {return it.name}).sort(); }
- function getGemsOfColor(color, gems) {
let temp_gems = [];gems.filter(gem => gem.colors.includes(color)).forEach(gem => temp_gems.push(gem.name));return temp_gems;- return gems.filter(gem => gem.colors.includes(color)).map(it => {return it.name}).sort();
- }
// TODO: Add your tests here // Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework. // [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework) // are still available for now. // // For new tests, using [Chai](https://chaijs.com/) is recommended. // You can use it by requiring: // const assert = require("chai").assert; // If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted. const assert = require("chai").assert; describe("Sample test cases", function() { const gems = [ { name: 'Emerald', colors: 'green' }, { name: 'Amethyst', colors: 'purple' }, { name: 'Garnet', colors: ['orange', 'red']}, { name: 'Aquamarine', colors: ['blue', 'green']}, ]; it("Get all blue gems", function() { assert.deepEqual(getGemsOfColor('blue', gems), ['Aquamarine']); }); it("Get all green gems", function() { assert.deepEqual(getGemsOfColor('green', gems), ['Aquamarine', 'Emerald']); }); it("Get all white gems (empty)", function() { assert.deepEqual(getGemsOfColor('white', gems), []); }); });
- // TODO: Add your tests here
- // Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
- // [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
- // are still available for now.
- //
- // For new tests, using [Chai](https://chaijs.com/) is recommended.
- // You can use it by requiring:
- // const assert = require("chai").assert;
- // If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
- const assert = require("chai").assert;
- describe("Sample test cases", function() {
- const gems = [
- { name: 'Emerald', colors: 'green' },
- { name: 'Amethyst', colors: 'purple' },
- { name: 'Garnet', colors: ['orange', 'red']},
- { name: 'Aquamarine', colors: ['blue', 'green']},
- ];
- it("Get all blue gems", function() {
assert.strictEqual(getGemsOfColor('blue', gems), ['Aquamarine']);- assert.deepEqual(getGemsOfColor('blue', gems), ['Aquamarine']);
- });
- it("Get all green gems", function() {
assert.strictEqual(getGemsOfColor('green', gems), ['Aquamarine', 'Emerald']);- assert.deepEqual(getGemsOfColor('green', gems), ['Aquamarine', 'Emerald']);
- });
- it("Get all white gems (empty)", function() {
assert.strictEqual(getGemsOfColor('white', gems), []);- assert.deepEqual(getGemsOfColor('white', gems), []);
- });
- });