You like to play card games, But this game has simple rules, There are 40 cards within it, 4 for each number from 1 to 10.
You have a function that takes two arguments: The card the player has played, and the cards on the floor.
If the player's card was equal to any of the cards on the floor or the sum of any cards on the floor, All These cards should be taken from the floor
For example: The player threw a 7 card on the floor.
There were cards: [ 6, 1, 3, 4 ] on the floor.
Since both the combinations [6, 1] and [4, 3] are equal to 7, Then all of them should be returned by the function.
But, If there were : [ 2 ,4, 1, 3 ] cards .
You can only take the sequence [2, 4, 1] from the floor. Not 3.
because after removing the three initial cards no 4s will be left for a 3 card to add up to the sum of 7.
Notice that we've chosen: [ 2, 4, 1 ]. Because they have a higher number of cards than the sequence [4, 3].
You need to write an algorithm that returns what should be taken from the floor if there were cards or sequences of cards that're equal to the player's card. And your time is short so what'll you do?
function GameOfCards(handCard, floorCards)
{
// your code here
}
// 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.
describe("Solution", function() {
it("should test for something", function() {
Test.assertEquals(GameOfCards(7, [3,4,1,2]), [4,1,2]);
Test.assertEquals(GameOfCards(7, [3,4,1]), [3,4]);
Test.assertEquals(GameOfCards(8, [1,9]), []);
Test.assertEquals(GameOfCards(9, [3,4,8,2,1]), [[3,4,2], [8,1]]);
Test.assertEquals(GameOfCards(3, [3,8,7,4,2,6]), [3]);
// assert.strictEqual(1 + 1, 2);
});
});