【Codility Lesson3】FrogJmp

[Codilityの勧め ~JavaScriptで解くアルゴリズム~](https://qiita.com/kyohei_ai/items/f4601cc6b55463565392)の実践編です。

## 問題

A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D.

Count the minimal number of jumps that the small frog must perform to reach its target.

Write a function:

function solution(X, Y, D);

that, given three integers X, Y and D, returns the minimal number of jumps from position X to a position equal to or greater than Y.

For example, given:

  X = 10
  Y = 85
  D = 30
the function should return 3, because the frog will be positioned as follows:

after the first jump, at position 10 + 30 = 40
after the second jump, at position 10 + 30 + 30 = 70
after the third jump, at position 10 + 30 + 30 + 30 = 100
Write an efficient algorithm for the following assumptions:

X, Y and D are integers within the range [1..1,000,000,000];
X ≤ Y.

### 語彙メモ
- `located at position X` 位置Xにあります
- `greater than or equal to Y` Y以上
- `must perform to reach its target.` ターゲットに到達するために実行しなければならない
- `Write an efficient algorithm for the following assumptions:` (:以下の)仮定のための効率的なアルゴリズムを書け


## 解法

### 必要知識

- **parseInt()**
- 三項演算子

太字にしているものは初見でした。

``` JavaScript
function solution(X, Y, D) {
  // write your code in JavaScript (Node.js 8.9.4)
  if (X >= Y) {
    return 0;
  } else if (D >= X + Y) {
    return 1;
  } else {
    let minimalJumps = parseInt((Y - X) / D);
    minimalJumps += (Y - X) % D > 0 ? 1 : 0;
    return minimalJumps;
  }
}
```

比較的簡単でした。

## 参考
https://gist.github.com/andhikamaheva/77e4a4bc393b594aa17856528fbe9764

<a href="//af.moshimo.com/af/c/click?a_id=1875799&amp;p_id=170&amp;pc_id=185&amp;pl_id=4062&amp;url=https%3A%2F%2Fwww.amazon.co.jp%2Fdp%2FB07179Q3MJ" rel="nofollow"><img src="https://images-fe.ssl-images-amazon.com/images/I/51ElwXwvJ-L._SL75_.jpg" alt="" style="border: none;" /><br />アルゴリズム図鑑 絵で見てわかる26のアルゴリズム</a><img src="//i.moshimo.com/af/i/impression?a_id=1875799&amp;p_id=170&amp;pc_id=185&amp;pl_id=4062" alt="" width="1" height="1" style="border: 0px;" />

<a href="//af.moshimo.com/af/c/click?a_id=1875799&amp;p_id=170&amp;pc_id=185&amp;pl_id=4062&amp;url=https%3A%2F%2Fwww.amazon.co.jp%2Fdp%2FB00FR78X64" rel="nofollow"><img src="https://images-fe.ssl-images-amazon.com/images/I/51bZA91ZWqL._SL75_.jpg" alt="" style="border: none;" /><br />世界でもっとも強力な9のアルゴリズム</a><img src="//i.moshimo.com/af/i/impression?a_id=1875799&amp;p_id=170&amp;pc_id=185&amp;pl_id=4062" alt="" width="1" height="1" style="border: 0px;" />

<a href="//af.moshimo.com/af/c/click?a_id=1875799&amp;p_id=170&amp;pc_id=185&amp;pl_id=4062&amp;url=https%3A%2F%2Fwww.amazon.co.jp%2Fdp%2FB01N14WBX3" rel="nofollow"><img src="https://images-fe.ssl-images-amazon.com/images/I/61bXMHbyv3L._SL75_.jpg" alt="" style="border: none;" /><br />なっとく！アルゴリズム</a><img src="//i.moshimo.com/af/i/impression?a_id=1875799&amp;p_id=170&amp;pc_id=185&amp;pl_id=4062" alt="" width="1" height="1" style="border: 0px;" />

<a href="//af.moshimo.com/af/c/click?a_id=1875799&amp;p_id=170&amp;pc_id=185&amp;pl_id=4062&amp;url=https%3A%2F%2Fwww.amazon.co.jp%2Fdp%2F4873117836" rel="nofollow"><img src="https://images-fe.ssl-images-amazon.com/images/I/51U44SJi3jL._SL75_.jpg" alt="" style="border: none;" /><br />初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発</a><img src="//i.moshimo.com/af/i/impression?a_id=1875799&amp;p_id=170&amp;pc_id=185&amp;pl_id=4062" alt="" width="1" height="1" style="border: 0px;" />

<a href="//af.moshimo.com/af/c/click?a_id=1875799&amp;p_id=170&amp;pc_id=185&amp;pl_id=4062&amp;url=https%3A%2F%2Fwww.amazon.co.jp%2Fdp%2FB01MZ9MGRV" rel="nofollow"><img src="https://images-fe.ssl-images-amazon.com/images/I/41i2cQpdbPL._SL75_.jpg" alt="" style="border: none;" /><br />徹底例解ロイヤル英文法　改訂新版</a><