危机】Century Crisis"/>
0060【Edabit ★☆☆☆☆☆】【世纪危机】Century Crisis
0060【Edabit ★☆☆☆☆☆】【世纪危机】Century Crisis
algorithms
loops
math
Instructions
Scientists have discovered that in four decades, the world will EXPLODE! It will also take three decades to make a spaceship to travel to a new planet that can hold the entire world population.
You must calculate the number of people there will be in three decades from now.
- The variable
population
is the world population now.- Assume that every month, someone gives birth to more people
n
.Return the number of people there will be when the spaceship is complete.
Examples
futurePeople(256, 2) // 976
futurePeople(3248, 6) // 5408
futurePeople(5240, 3) // 6320
Notes
- Humanity’s fate lies in your calculation.
Solutions
function futurePeople(population, n) {return population + 30*12*n;
}
TestCases
let Test = (function(){return {assertEquals:function(actual,expected){if(actual !== expected){let errorMsg = `actual is ${actual},${expected} is expected`;throw new Error(errorMsg);}},assertSimilar:function(actual,expected){if(actual.length != expected.length){throw new Error(`length is not equals, ${actual},${expected}`);}for(let a of actual){if(!expected.includes(a)){throw new Error(`missing ${a}`);}}}}
})();Test.assertEquals(futurePeople(256, 2), 976)
Test.assertEquals(futurePeople(3248, 6), 5408)
Test.assertEquals(futurePeople(5240, 3), 6320)
更多推荐
0060【Edabit ★☆☆☆☆☆】【世纪危机】Century Crisis
发布评论