-
Description Find the bomb inside the list of boxes. a Box can contains boxes, in other word
Recursive
. You need to find the bomb and than give the box code, so the CIA agent can defuse it.constraints:
should throw an error if sent empty array should return solution with string format ([Box_code] >?)+, example: "B1 > B1.3 > B1.3.1 ... B.n"
Code interface ListOfBoxes { code: string, bomb?: boolean, boxes?: ListOfBoxes[] } export function findTheBomb (listOfBoxes: ListOfBoxes[]): string{ // You Can Code Below Here return `` }
Test Cases Failed // Since Node 10, we're using Mocha. // You can use `chai` for assertions. const chai = require("chai"); const assert = chai.assert; // Uncomment the following line to disable truncating failure messages for deep equals, do: // chai.config.truncateThreshold = 0; // Since Node 12, we no longer include assertions from our deprecated custom test framework by default. // Uncomment the following to use the old assertions: // const Test = require("@codewars/test-compat"); import { findTheBomb } from "./solution"; interface ListOfBoxes { code: string, bomb?: boolean, boxes?: ListOfBoxes[] } const listBoxes1: ListOfBoxes[] = [ { code: "B1", boxes: [ { code: "B1.1" }, { code: "B1.2" } ] }, { code: "B2", boxes: [ { code: "B2.1", boxes: [ { code: "B2.1.1" }, { code: "B2.1.2", bomb: true } ] }, { code: "B2.2" } ] } ] const listBoxes2: ListOfBoxes[] = [ { "code": "B1.2", "boxes": [ { "code": "B1.2.2", "boxes": [ { "code": "B1.2.2.6" } ] }, { "code": "B1.2.7" }, { "code": "B1.2.4" }, { "code": "B1.2.0" }, { "code": "B1.2.9", "boxes": [ { "code": "B1.2.9.0", "bomb": true, } ] } ] }, { "code": "B2.8", "boxes": [ { "code": "B2.8.0" }, { "code": "B2.8.7" }, { "code": "B2.8.6" }, { "code": "B2.8.3" } ] }, { "code": "B3.6", "boxes": [ { "code": "B3.6.5" }, { "code": "B3.6.7", "boxes": [ { "code": "B3.6.7.9" } ] } ] } ] const listBoxes3: ListOfBoxes[] = [ { "code": "B1.6", "boxes": [ { "code": "B1.6.9" }, { "code": "B1.6.2" } ] }, { "code": "B2.4", "boxes": [ { "code": "B2.4.0" }, { "code": "B2.4.3", "boxes": [ { "code": "B2.4.3.9", "bomb": true } ] }, { "code": "B2.4.7" } ] } ] describe("Find The Bomb", function() { it("should return `No Boxes No Bomb!` if give empty arrays as arg", function () { const result = findTheBomb([]) assert.strictEqual(result, "No Boxes No Bomb!") }) it("should return with format `([BOX_CODE] >?)+` listOfBoxes1", function () { const result = findTheBomb(listBoxes1) assert.strictEqual(result, "B2 > B2.1 > B2.1.2") }) it("should return with format `([BOX_CODE] >?)+` listOfBoxes2", function () { const result = findTheBomb(listBoxes2) assert.strictEqual(result, "B1.2 > B1.2.9 > B1.2.9.0") }) it("should return with format `([BOX_CODE] >?)+` listOfBoxes3", function () { const result = findTheBomb(listBoxes3) assert.strictEqual(result, "B2.4 > B2.4.3 > B2.4.3.9") }) });
Output:
-
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
Please sign in or sign up to leave a comment.