https://www.freecodecamp.com/challenges/stand-in-line
ํธ์ ๋ฐ ์ํํธ ๊ธฐ๋ฅ์ ์ฌ์ฉํ ๋ ์ ํจ์ฑ ๊ฒ์ฌ "nextInLine([5,6,7,8,9], 1) must return 5"๋ ๋ด๊ฐ ํ๋ ธ๋ค๋ ๊ฒ์ ๋ณด์ฌ์ค๋๋ค.
๊ทธ๋ฌ๋ testArr์ ๋ฐฐ์ด '[5,6,7,8,9]'๋ฅผ ์๋์ผ๋ก ์ฝ์
ํ๊ณ ํจ์ ํธ์ถ ์ ์ธ์ '1'์ ์ฝ์
ํ๋ฉด '5'๊ฐ ๋ฐํ๋ฉ๋๋ค.
function nextInLine(arr, item) {
testArr.push(item);
item = testArr.shift();
return item; // Change this line
}
var testArr = [5,6,7,8,9];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
testArr์ด ์๋ ํจ์์์ ๋งค๊ฐ๋ณ์๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค.
๊ทํ์ ์ฝ๋:
function nextInLine(arr, item) {
testArr.push(item);
item = testArr.shift();
return item; // Change this line
}
์ฌ๋ฐ๋ฅธ ์ฝ๋:
function nextInLine(arr, item) {
arr.push(item);
return arr.shift(); // Change this line
}
์๊ฒ ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๊ทํ์ ์ฝ๋:
์ฌ๋ฐ๋ฅธ ์ฝ๋: