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"
interface ListOfBoxes {
code: string,
bomb?: boolean,
boxes?: ListOfBoxes[]
}
export function findTheBomb (listOfBoxes: ListOfBoxes[]): string{
// You Can Code Below Here
return ``
}
// 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")
})
});
I Have An Array With Type Number
const point: number = [20, 10, 100, 40, 5, 50];
Can You Filter To Show Data With Criteria On Below:
- More Than Equal 10
- More Than Equal 40
- More Than Equal 100
export function filteringDataMoreThanEqual (data: number[], comparator: number): string{
return String(data);
}
// See https://www.chaijs.com for how to use Chai.
import { assert } from "chai";
import { filteringDataMoreThanEqual } from "./solution";
const point: number[] = [20, 10, 100, 40, 5, 50];
const answer1: number[] = [20, 10, 100, 40, 50];
const answer2: number[] = [100, 40, 50];
const answer3: number[] = [100];
// TODO Add your tests here
describe("Checking Test Nagatech #5", function() {
it("Checking Test Filter Array Function", function() {
assert.strictEqual(filteringDataMoreThanEqual(point, 10), `${answer1}`);
assert.strictEqual(filteringDataMoreThanEqual(point, 40), `${answer2}`);
assert.strictEqual(filteringDataMoreThanEqual(point, 100), `${answer3}`)
// assert.strictEqual(1 + 1, 2);
});
});
I Have An Array With Type iType On Below Here
interface iType {
subject: string,
point: number
}
const data: iType[] = [
{
subject: "IPA",
point: 70,
},
{
subject: "MTK,
point: 65
}
];
Can You Find The Value Of The data Above Using Following Formula:
value = total_of_point / total_of_data;
export interface iType {
subject: string,
point: number
}
export function valueResult (data: iType[]): number {
let value = 0;
// You Can Code Below Here
return value;
}
// See https://www.chaijs.com for how to use Chai.
import { assert } from "chai";
import { valueResult, iType } from "./solution";
const data: iType[] = [
{
subject: "IPA",
point: 70,
},
{
subject: "MTK",
point: 65
}
];
describe("Checking Test Nagatech Basic #4", function() {
it("Checking Test On Array Function", function() {
assert.strictEqual(valueResult(data), 67.5)
});
});
I Have An Array With Types From Interface iType
interface iType{
id: number,
name: string,
};
const data: iType[] = [
{
id: 1
name: "Manny"
},
{
id: 2
name: "Danny"
},
{
id: 3
name: "Socciella"
},
];
Can You Show Only One Data From That Array By ID?
export interface iType{
id: number,
name: string,
}
export function findData (data: iType[], selectedData: number): iType {
// You Can Code Here
}
// See https://www.chaijs.com for how to use Chai.
import { assert } from "chai";
import { findData, iType } from "./solution";
const data: iType[] = [
{
id: 1,
name: "Manny"
},
{
id: 2,
name: "Danny"
},
{
id: 3,
name: "Socciella"
},
];
// TODO Add your tests here
describe("Checking Test Nagatech Basic 3", function() {
it("Status", function() {
assert.strictEqual(findData(data, 1), data[0]);
assert.strictEqual(findData(data, 2), data[1]);
});
});
Search The Longest Word
from a sentence. if there's 2 or more word with same largest length, you need to return no longest word found
,
example:
I really love to learn and do experiment with typescript
here, experiment
and typescript
have the same length 9
.
so the solution is no longest word found
.
constraints:
- should throw an error if sent empty argument
- should throw an error if sent non string argument
- should return solution with string format
[word]: [length] chars
- should return
no longest word found
if there's 2 or more word found.
export function findTheLongestWord (sentence?: string): string{
// You Can Code Below Here
return ``
}
// See https://www.chaijs.com for how to use Chai.
import { assert } from "chai";
import { findTheLongestWord } from "./solution";
// TODO Add your tests here
describe("Longest Word Unit Test", function() {
it("should throw an error if sent empty argument", function() {
assert.throws(() => findTheLongestWord())
});
it("should return solution with string format `[word]: [length]`", function () {
const result = findTheLongestWord("I love Nagatech")
assert.strictEqual(result, "Nagatech: 8 chars")
})
it("should return `no longest word found` if there's 2 or more word found", function () {
const result = findTheLongestWord("Programmer use Typescript")
assert.strictEqual(result, "no longest word found")
})
});
describe("Longest Word Bonus Test", function () {
it("Bonus #1", function (){
const result = findTheLongestWord("Determine the Injustice")
assert.strictEqual(result, "no longest word found")
})
it("Bonus #2", function() {
const result = findTheLongestWord("Nagatech Sistem Integrator")
assert.strictEqual(result, "Integrator: 10 chars")
})
it("Bonus #3", function() {
const result = findTheLongestWord("NGTC")
assert.strictEqual(result, "NGTC: 4 chars")
})
it("Bonus #4", function() {
const result = findTheLongestWord("Kamu suka Typescript")
assert.strictEqual(result, "Typescript: 10 chars")
})
})
I Have a Constants With Type String There's On Below
const text: string1 = "B0002";
const text: string2 = "B0000001";
const text: string3 = "B0000004";
Can You Take The Number And Convert it To Number Type
export function takeANumber (text: string): number {
// Don't Change This Variable
let result: number = 0;
// You Can Code Below Here
return result;
}
// See https://www.chaijs.com for how to use Chai.
import { assert } from "chai";
import { takeANumber } from "./solution";
// TODO Add your tests here
describe("Testing_1", function() {
it("Checking Code", function() {
// assert.strictEqual(1 + 1, 2);
assert.strictEqual(takeANumber("B0002"), 2);
assert.strictEqual(takeANumber("B0000001"), 1);
assert.strictEqual(takeANumber("B0000004"), 4);
});
});
I Have A String There's In Below
const array: string = "I Love Typescript";
Can You Take The First Word From These Text?
export function takeFirstWord (text: string) {
}
// See https://www.chaijs.com for how to use Chai.
import { assert } from "chai";
import { takeFirstWord } from "./solution";
// TODO Add your tests here
describe("Testing_1", function() {
it("Checking Code", function() {
// assert.strictEqual(1 + 1, 2);
assert.strictEqual(takeFirstWord("I Love Typescript"), "ILT")
});
});