Arrays and programming styles Flashcards

1
Q

zero based array

A
  • the first value in an array is 0, not 1

first slot would have an idea of 0
2nd slot would have an index of 1
3rd index would have an index of 2
etc..

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

array

A

a collection of values wrapped up under one named variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

programming language with a 1 based index (1)

A

visual basic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how to write an array in javascript (easy way)

A
var a = [ ];
a[0] = Apple;
a[1] = iPod;
a[2] = 77;

now, a[0] = Apple and so on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

how to write an array (fast way)

A

var a = [“Apple”, “iPod”, 77]; [0] [1] [2]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

an array is often referred to as

A

a collection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

in javascript, arrays are…

A

objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

if there are 5 items in an index, the highest # index is

A

4

0, 1, 2, 3, 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

method

A

a function that belongs to an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what does the .reverse method do?

suppose:

a.reverse ( );

A

it would reverse the order of the array

Apple(0), iPad(1), 77(2)&raquo_space; 77(0), iPad(1), Apple(2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what does .sort method do?

suppose:

a.sort ( );

A

it would sort an array based on the rules of the programming language

alphabetical, numeric, or a mixture.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what does .join method do?

suppose:

a.join ( );

A

returns an array separated with commas as a character string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what does .pop method do?

suppose:

var b = a.pop ( );

A

would take the last value of an array, remove it from the array, and set b = the last value of the array that was just removed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what does .push method do?

suppose:

a.push (123);

A

123 would be added as a new index to he array in a new index slot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

who wrote the “book” on javascript?

A

Mozilla, they own it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

iteration

A

a loop

17
Q

mutable object

A
  • an object that can mutate or change
18
Q

immutable object

A
  • an object that cannot change or mutate
19
Q

in javascript, the arrays are … mutable or immutable?

A

mutable

NOTE* javascript is the exception to the rule. most programming languages do not allow you to modify arrays once they are created

20
Q

what are the benefits of immutable arrays?

A
  • faster
  • less prone to error – an array for a week would want 7 days or 7 values. it would never make sense to have an array for days of the week to change.
21
Q

Generally, you want your code to be (3)

A

1) readable
2) consistent
3) accepted best practice

22
Q

camelcase

A

highScore
uglyDuck
mySQL
cityNailAndSpa

The standard for variable naming in javascript

23
Q

javascript (5) best practices

A

1) use camel case for variables, functions, and methods
2) open curly braces on the same line
3) define function before you call them
4) always use semicolons at the end of your statement
5) always use var when creating a variable

24
Q

pseudocode

A

the process of writing down your code in plain english to see the problems you have to solve