Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:33
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • May 10 09:13
    @bjorno43 banned @zhaokunhaoa
  • Apr 25 17:12
    @mstellaluna banned @cmal
  • Apr 01 18:11
    thecodingaviator labeled #31179
  • Apr 01 18:11
    thecodingaviator labeled #31179
  • Apr 01 18:09
    thecodingaviator commented #31179
  • Apr 01 18:09
    thecodingaviator labeled #31182
  • Apr 01 18:09
    thecodingaviator labeled #31182
  • Apr 01 18:07
    thecodingaviator commented #31182
  • Apr 01 18:07
    thecodingaviator labeled #31190
  • Apr 01 18:07
    thecodingaviator labeled #31190
  • Apr 01 18:07
    thecodingaviator commented #31190
  • Apr 01 18:05
    thecodingaviator commented #31157
  • Apr 01 18:04

    thecodingaviator on master

    remove A (#31157) (compare)

  • Apr 01 18:04
    thecodingaviator closed #31157
  • Apr 01 18:04
    thecodingaviator closed #33788
  • Apr 01 18:04
    thecodingaviator commented #33788
  • Apr 01 18:02
    thecodingaviator closed #31059
  • Apr 01 18:02
    thecodingaviator commented #31059
Arnaud Casamé
@arnaudcasame
???
KT
@Krystinet
right
MoNag1
@MoNag1
@djcase001 i believe its under basic javascript?
KT
@Krystinet
Yes javascript
MoNag1
@MoNag1
@Krystinet ok next you need to find a way to remove the first element of an array, do you know any way that could be done?
KT
@Krystinet
.pop
MoNag1
@MoNag1
@Krystinet close, pop removes last element
what you're looking for is shift
KT
@Krystinet
Right!
(sorry I did those sections twice but haven't gone back in about a week!)
MoNag1
@MoNag1
dw we all forget, do you know how you can apply .shift()?
KT
@Krystinet
variableName.shift()?
Joseph
@revisualize

@cdomiano Here is the code that you posted:

function slasher(arr, howMany) {
 arr.slice(0);
arr= arr.splice(howMany);

  return arr
  ;
}

Let's evaluate

function slasher(arr, howMany) {
 arr.slice(0);          // this does nothing. So, it isn't needed.
arr= arr.splice(howMany);
                        // assigning a thinger to a thing just to return the thing is pointless.
  return arr
  ;
}

So, we can refactor all of that to...

function slasher(arr, howMany) {
  return arr.splice(howMany);
}

But, that's just my thoughts. I could be wrong.
const slasher = (a, h) => a.splice(h);

Arnaud Casamé
@arnaudcasame
@MoNag1 @Krystinet you have to use two array methods to solve this problem
Joseph
@revisualize
grrrrr.
MoNag1
@MoNag1
@Krystinet yep, and your variable name is arr, so do that
Joseph
@revisualize
There.
MoNag1
@MoNag1
@djcase001 yea .push() and .shift()
Joseph
@revisualize
@cdomiano ------^^^^^^ :D
KT
@Krystinet
@MoNag1 @djcase001 arr.shift()
arr.push()
so that part I understand
Joseph
@revisualize
@Krystinet You have it backwards.
KT
@Krystinet
Okay
Joseph
@revisualize

https://gist.github.com/revisualize/ced4a3a6611c6c74bcab34a07eaa4ebf
Parameters are variables that represent the values that get passed into your function from the function call.
https://cs.wellesley.edu/~cs110/lectures/L16/images/function-anatomy.png
Notice how the variables level and score in the function definition addScore are called parameters.
However, when we invoke the function like in:
addScore(3, 10) or addScore(6, 20)
the values are called arguments. Here is an important lesson:
You define a function with parameters, you call a function with arguments.

Another example of this:

function hello(fName, uName) {
     return "Hello " + fName + " " + uName + ", How is your day?";
}
hello("Joseph", "@revisualize"); // "Hello Joseph @revisualize, How is your day?"
hello("Bella", "@bellaknoti"); // "Hello Bella @bellaknoti, How is your day?"
hello("Andy", "@dirn"); // "Hello Andy @dirn, How is your day?"

You can use the fName and uName parameters just like a variable inside of your function.

Other important things to remember:
* A function can have zero parameters. You still have to use the parentheses to define it.
* A function might have no return statements. In this case we say that the function returns undefined.
....

var name = function() { return "Joseph"; }

The push() method adds one or more elements to the end of an array and returns the new length of the array.

The pop() method removes the last element from an array and returns that element.

The shift() method removes the first element from an array and returns that element.

The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

MoNag1
@MoNag1
@Krystinet alright send your code knowing what you know now
Arnaud Casamé
@arnaudcasame
@Krystinet first push the item, and then shift the array into item
Joseph
@revisualize
But, you know.. meh.
KT
@Krystinet
Do I have to set arr and item to something?
Arnaud Casamé
@arnaudcasame
@Krystinet
Joseph
@revisualize
@Krystinet No.
@Krystinet They are parameters.
You know.. That big block of text that I just posted. With images ans stuff.
Arnaud Casamé
@arnaudcasame
@revisualize loll
KT
@Krystinet
sorry guys, im really being dense on this one

function nextInLine(arr, item) {
// Your code here
arr.push();
item.shift();
return item; // 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));

Joseph
@revisualize
@Krystinet item isn't an array.
MoNag1
@MoNag1
@Krystinet you should shift arr and not item
Joseph
@revisualize
@Krystinet function nextInLine which has two parameters an array (arr) and a number (item).
MoNag1
@MoNag1
@Krystinet also, you will need a place to store the new array after the first item has been removed
Arnaud Casamé
@arnaudcasame
@Krystinet
item = arr.shift()
KT
@Krystinet

function nextInLine(arr, item) {
// Your code here
arr.shift();
arr.push();
return item; // 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));

Joseph
@revisualize
@Krystinet Why did you change the order?
KT
@Krystinet
Ahhh
I DONT KNOW
jrr5230
@jrr5230
@Krystinet I think you should take the time to understand the whole block of info that @revisualize posted :)
Joseph
@revisualize
@Krystinet :point_up: November 22, 2016 7:26 PM
Arnaud Casamé
@arnaudcasame
@Krystinet
KT
@Krystinet

function nextInLine(arr, item) {
// Your code here
item = arr.push();
item = arr.shift();
return item; // 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));

Joseph
@revisualize
@Krystinet Why are you overwriting item?