For me that is the 2nd test. The 1st test passes which is
nextInLine([], 1) should return 1
For me that is the 2nd test. The 1st test passes which is
nextInLine([], 1) should return 1
So howcome this wouldnāt work?
function nextInLine(arr, item) {
// Your code here
.pop([2], 1);
return nextInLine; // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
.pop should be added to the array so
myArray.pop();
is the correct syntax. Read the docs!
return nextInLine;
nextInLine is a function so why return the name of the function??
You are asked to return the item removed last. Imagine a queue.
Sorry, I meant this, pasted the wrong code
function nextInLine(arr, item) {
// Your code here
.push(testArr).pop(testArr);
return nextInLine; // Change this line
}
// Test Setup
var testArr = [1,2,3,4,5];
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Dude, itās confusing as hell, you have no idea.
Itās the process itself, thereās no guidelines as to how to go about what process to take and I think thatās why Im getting hardcore confused. Itās just a bunch of mumbo jumbo scrambled together that means nothing basically. By nothing I mean random numbers and the word array and num in the problem itself etc.
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array
You can do this with arr.push(item);
https://www.w3schools.com/jsref/jsref_push.asp
Hereās waht I would write to your instruction above.
function nextInLine(arr, 23) {
var array = [1,2,3];
array.push([4]);
}
nextInLine();
The next part:
then remove the first element of array.
You can do this with var x = arr.shift();
as the return from the shift function will be saved in var x;
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_shift_return
Full solution:
Not sure what you mean by āsaved in var xā because thereās no storage device involved but here what I would do then.
function nextInLine(arr, 23) {
var array = [1,2,3];
array.push([4]);
array.shift([0]);
}
nextInLine();
I did [0] to remove the first number in the array.
You donāt actually need var x. You can return the value out of the function if you know that method?
Anyway. I am off to bed. You might get some help in the gitter chat if you still need.
Below is my first step
nextInLine([2], 1) should return 2
Itās telling me what it āshouldā be, but how am I supposed to know what to actually start writing? Like how do you take a problem and automatically āknowā what to start writing to solve the problem? Like do I start with a function or a variable or a loop or an if/else or how do you know what to start writing?
For example, the first step (above) says nextInLine([2], 1) but I donāt even see where it says that or is displayed like that in the actual problem at all. This makes no sense literally at all.
Okay, hey man, thanks for taking the time to try and explain it though. I appreciate it.
Dude Iām right there with you. I donāt understand this at all and none of these explanations are helping.