javascript 代码2017年出现 - 第5天

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 代码2017年出现 - 第5天相关的知识,希望对你有一定的参考价值。

// Day 5 - Challenge #2
// input is an array of integers
function escapeHops2(input) {
	let hops = 0;
	for (let pos = 0; pos < input.length;) {
		const prevPos = pos;
		pos += input[pos];
		hops += 1;
		input[prevPos] += (input[prevPos] >= 3 ? -1 : 1);
	}
	return hops;
}
// Day 5 - Challenge #1
// input is an array of integers
function escapeHops(input) {
	let hops = 0;
	for (let pos = 0; pos < input.length;) {
		const prevPos = pos;
		pos += input[pos];
		hops += 1;
		input[prevPos]++;
	}
	return hops;
}

以上是关于javascript 代码2017年出现 - 第5天的主要内容,如果未能解决你的问题,请参考以下文章