2021-02-06 04:42:36 +00:00
---
id: 56533eb9ac21ba0edf2244c6
2021-03-09 08:51:59 -07:00
title: Permanece en línea
2021-02-06 04:42:36 +00:00
challengeType: 1
videoUrl: 'https://scrimba.com/c/ca8Q8tP'
forumTopicId: 18307
dashedName: stand-in-line
---
# --description--
2021-03-09 08:51:59 -07:00
En Informática una < dfn > cola< / dfn > (queue) es una estructura de datos < dfn > abstracta< / dfn > donde los elementos se mantienen en orden. Los nuevos elementos se pueden añadir en la parte posterior de la cola y los elementos antiguos se retiran de la parte delantera de la cola.
2021-02-06 04:42:36 +00:00
2022-02-23 18:40:00 +05:30
# --instructions--
2021-03-09 08:51:59 -07:00
Escribe una función `nextInLine` que tome un arreglo (`arr` ) y un número (`item` ) como argumentos.
2021-02-06 04:42:36 +00:00
2021-03-09 08:51:59 -07:00
Agrega el número al final del arreglo, luego elimina el primer elemento del arreglo.
2021-02-06 04:42:36 +00:00
2021-03-09 08:51:59 -07:00
La función `nextInLine` debe entonces devolver el elemento que fue removido.
2021-02-06 04:42:36 +00:00
# --hints--
2021-03-09 08:51:59 -07:00
`nextInLine([], 5)` debe devolver un número.
2021-02-06 04:42:36 +00:00
```js
assert.isNumber(nextInLine([], 5));
```
2021-03-09 08:51:59 -07:00
`nextInLine([], 1)` debe devolver `1`
2021-02-06 04:42:36 +00:00
```js
assert(nextInLine([], 1) === 1);
```
2021-03-09 08:51:59 -07:00
`nextInLine([2], 1)` debe devolver `2`
2021-02-06 04:42:36 +00:00
```js
assert(nextInLine([2], 1) === 2);
```
2021-03-09 08:51:59 -07:00
`nextInLine([5,6,7,8,9], 1)` debe devolver `5`
2021-02-06 04:42:36 +00:00
```js
assert(nextInLine([5, 6, 7, 8, 9], 1) === 5);
```
2021-03-09 08:51:59 -07:00
Después de `nextInLine(testArr, 10)` , `testArr[4]` debe ser igual a `10`
2021-02-06 04:42:36 +00:00
```js
nextInLine(testArr, 10);
assert(testArr[4] === 10);
```
# --seed--
## --before-user-code--
```js
var logOutput = [];
var originalConsole = console
function capture() {
var nativeLog = console.log;
console.log = function (message) {
logOutput.push(message);
if(nativeLog.apply) {
nativeLog.apply(originalConsole, arguments);
} else {
var nativeMsg = Array.prototype.slice.apply(arguments).join(' ');
nativeLog(nativeMsg);
}
};
}
function uncapture() {
console.log = originalConsole.log;
}
capture();
```
## --after-user-code--
```js
uncapture();
testArr = [1,2,3,4,5];
(function() { return logOutput.join("\n");})();
```
## --seed-contents--
```js
function nextInLine(arr, item) {
// Only change code below this line
return item;
// Only change code above this line
}
// Setup
2021-10-27 15:10:57 +00:00
const testArr = [1, 2, 3, 4, 5];
2021-02-06 04:42:36 +00:00
// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));
```
# --solutions--
```js
2021-10-27 15:10:57 +00:00
const testArr = [1, 2, 3, 4, 5];
2021-02-06 04:42:36 +00:00
function nextInLine(arr, item) {
arr.push(item);
return arr.shift();
}
```