Skip to content

Instantly share code, notes, and snippets.

View goodbedford's full-sized avatar

goodbedford goodbedford

View GitHub Profile
var numOfCars = 50;
var numOfDrivers = 25;
if (numOfCars) {
console.log("We have", numOfCars, "to race.");
}
if (numOfCars < 50) {
console.log("never called");
// join( seperator)
// seperator is optional, defaults to coma; use "" empty string to combine without spaces.
var someArray = ["a", "b", "c", 4, 5, ["bob", "bill"]];
var noSpace;
var hyphenated;
var commaSpace;
noSpace = someArray.join("");
// splice( starting-index, delete-count, new-item)
// start is index exact, delete-count is how many elements to remove including start
// new-item is optional and is added at starting-index
// splice is permenant
var dogs = ["Pit Bull", " American Cocker Spaniel", "Beagle", " Belgian Malinois"];
var newDog = "Bloodhound";
var guideDog = "Brussels Griffon"
// take out Beagle
dogs.splice(2,1);
var week = ["sun", "mon", "tue", "wed", "th", "fri", "sat"];
var workWeek = [];
//we want only mon-fri
workWeek = week.slice(1,6);
console.log("work week:", workWeek);
week[1] = "monday";
console.log("week",week);
console.log("work week:", workWeek);
// remember array index starts at zero
var rsvps = ["tracy", "bedford", "christina", "nicole", "lisa", "mark", "aaron", "marina"];
var girls = [];
console.log("\nnew party rsvps", rsvps);
// Pop Quiz: Make a list of girls for the after party using someArray[index] and push
// ------ add code below this line--------------------
girls.push( rsvps[0], rsvps[2], rsvps[3], rsvps[4], rsvps[7]);
@goodbedford
goodbedford / js-array-pop-shift-quiz.js
Last active August 6, 2016 05:59
js-array-pop-shift-quiz.js
// remember array index starts at zero
var rsvps = ["tracy", "bedford", "christina", "nicole", "lisa", "mark", "aaron", "marina"];
var girls = [];
console.log("new party rsvps", rsvps);
// Pop Quiz: Make a list of girls for the after party using someArray[index] and push
// ------ add code below this line--------------------
// to slice to copy part of an array
var rsvps = ["julie", "greg", "jess", "nicole", "kenn", "al", "angelina", "boo balm"];
// make a new list for the guys only after party
var guys = [];
guys.push( rsvps.slice(1,1).join("")); //greg
guys.push( rsvps.slice(3,1).join("")); //kenn
guys.push( rsvps.slice(3,1).join("")); //al
console.log("guys after-party", guys);
var rsvps = ["julie", "greg", "jess", "nicole", "kenn", "al", "angelina", "boo balm"];
console.log("rsvps:", rsvps);
// we need to add Dave to the end of party list
rsvps.push("dave");
console.log("after adding dave:", rsvps);
// julie can't make it, lets take her off the top
var carList = ["tesla", "bmw", "ford", "kia", "honda"];
// what car is at index 2?
console.log("What car is at index 2?", carList[2]);
var listOfFruit = ["apples", "pear", "lemons", "lychee"];
// what will the # of items be?
console.log("I have", listOfFruit.length, "things on my list.");