Nigelius is a new Hero in Mobile Legends, and you are invited for an interview by Shanghai Moonton
Technology for a game developer position. Nigelius the Bloodborn has a passive skill that increases
his damage for every 250 HP he has, and your task is to code this skill. The increase goes as
follows:
at 250 HP +1 damage
at 500 HP +4 damage
at 750 HP +9 damage
at 1000 HP +16 damage
at 1250 HP +25 damage
.
.
.
at 2000 HP +64 damage
at 2250 HP +81 damage
...etc
That is, we determine how many chunks of 250 HP Nigelius has, and then we square it to get the bonus
damage. Write a function getBonusDamage
given the current health of Nigelius.
Nigelius does not get fractional damage bonuses, in other words, 500 and 600 HP will give him +4
bonus damage. 749 HP will also give him +4 bonus damage.
function getBonusDamage(currentHP) {
return Math.trunc(currentHP / 250) ** 2
}
// 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");
describe('getBonusDamage', () => {
describe('Hidden Test Cases', () => {
it('___SE___works_for_HP_that_evenly_divides_250', () => {
assert.strictEqual(getBonusDamage(35750), 20449)
})
it('___SE___works_for_HP_that_does_not_evenly_divide_250_-_I', () => {
assert.strictEqual(getBonusDamage(67783), 73441)
})
it('___SE___works_for_HP_that_almost_creates_another_250_HP_chunk_-_I', () => {
assert.strictEqual(getBonusDamage(122488), 239121)
})
it('___SE___works_for_HP_that_does_not_evenly_divide_250_-_II', () => {
assert.strictEqual(getBonusDamage(125438), 251001)
})
it('___SE___works_for_HP_that_almost_creates_another_250_HP_chunk_-_II', () => {
assert.strictEqual(getBonusDamage(125249), 250000)
})
it('___SE___works_for_HP_that_does_not_evenly_divide_250_-_III', () => {
assert.strictEqual(getBonusDamage(232001), 861184)
})
it('___SE___works_for_HP_that_almost_creates_another_250_HP_chunk_-_III', () => {
assert.strictEqual(getBonusDamage(231998), 859329)
})
it('___SE___works_for_HP_that_does_not_evenly_divide_250_-_IV', () => {
assert.strictEqual(getBonusDamage(3586126), 205750336)
})
it('___SE___works_for_HP_That_almost_creates_another_250_HP_chunk_-_IV', () => {
assert.strictEqual(getBonusDamage(3585990), 205721649)
})
it('___SE___works_when_Nigelius_is_not_fine', () => {
assert.strictEqual(getBonusDamage(3), 0)
})
})
})