Freecodecamp: ์ค„ ์„œ๊ธฐ ์ฑŒ๋ฆฐ์ง€ - ์ž˜๋ชป๋œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ

์— ๋งŒ๋“  2016๋…„ 06์›” 24์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: freeCodeCamp/freeCodeCamp

์ฑŒ๋ฆฐ์ง€ ์ด๋ฆ„: ์ค„์„ ์„œ์„œ

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'๊ฐ€ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค.

๋ธŒ๋ผ์šฐ์ € ์ •๋ณด

  • ๋ธŒ๋ผ์šฐ์ € ์ด๋ฆ„, ๋ฒ„์ „: Chrome, 51.0.2704.84(64๋น„ํŠธ)
  • ์šด์˜ ์ฒด์ œ: ์šฐ๋ถ„ํˆฌ 14.04
  • ๋ชจ๋ฐ”์ผ, ๋ฐ์Šคํฌํƒ‘ ๋˜๋Š” ํƒœ๋ธ”๋ฆฟ: ๋ฐ์Šคํฌํƒ‘

์•”ํ˜ธ

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));

์Šคํฌ๋ฆฐ์ƒท

screenshot114

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

๊ท€ํ•˜์˜ ์ฝ”๋“œ:

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
}

๋ชจ๋“  3 ๋Œ“๊ธ€

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
}

์•Œ๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰