Data structures Flashcards

1
Q

What two main things replace internal tables in JS?

A

Arrays and Objects

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

How are items in an array separated?

A

By a comma

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

Give an example of defining an array

A

Let myArray = [“Bob”,”Tanya”,”Henry”]

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

What is the index of the first item in an array?

A

0

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

List 5 common array methods

A

.sort
.reverse
.some
.length
.push
.splice

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

Give the syntax for sorting an array of numbers by ascending and descending order

A

//sort a number array
Let myArray = [“C”,”D”,”A”,”B”]
myArray.sort(a, b) => a - b); //ascending
myArray.sort((a, b) => b - a);//descending

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

Give the syntax for sorting a non-numeric array

A

//sort
Let myArray = [“Ann”,”Karen”,”Bobby”];
myArray.sort();
myArray.reverse();

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

What are the two optional parameters for sorting that must be used when sorting numbers?

A

a = current value
b = next value
so
myArray.sort((a, b) => a - b);
means compare the current value to the next value and if a - b if b is less than a then b needs to move in front of a.
myArray.sort((a, b) => b - a): would be a descending sort. If b is less than a then a should move in front of b as this is descending

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

Explain what the array.some function does and give an example of it’s syntax

A

The .some searches for a value in the array
Let myArray = [“Bob”,”Henry”,”Karen”]
//check for value Karen
Let found = myArray.some((element) => element === “Karen”);
//Found will have a value of true

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

Give an example of the .length function

A

let myArray = [“bob”,”henry”,”tanya”];
let myLen = myArray.length();
//mylen will equal 3

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

give an example of the .push function

A

Let myArray = [“Pasha”,”Misha”];
myArray.push(“Isa”);
//isa will be added to end of the array

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

How is an array written to the console?

A

Let myArray = [“Isa”,”Bob”];
console.table(myArray);

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

What does the splice function do and what is the syntax?

A

myArray.splice(
“what index should the insert be
“0 to many lines should be removed
“what should be added
)
//so add “pasha” as the second item
Let myArray = [“Isa”,”Misha”];
myArray.splice(1, 0, “Pasha”];

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

How can an item be deleted from an array?

A

let myArray = [“Pasha”,”Isa”,”Misha”];
myArray.splice(1,1);
//the above would remove “Isa”

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

How can an item be replaced in an array?

A

let myArray = [“cat1”,”cat2”,”dog1”]
myArray.splice(0,2,”Dog0”);
//cat1 and cat 2 will be replaced by Dog0
//or
myArray = [“cat”,”dog”,”lizard”];
myArray.splice(1,1,”Isa”,”Pepe”)
//now cat, isa, pepe, lizard

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

What does an object in javascript relate to in ABAP?

A

A structure

17
Q

what does an object in JS consist of?

A

name:value pairs

18
Q

give an example of an object in JS

A

let dog = { breed: “Coton”, name:”Isa” };

19
Q

Can you give an example of an array that uses an object?

A

let dogArray = [
{
breed: “Coton”,
name: “isa”,
age: 11
},
{
breed: “collie”,
name: “Lassie”,
age: 14
},
];

20
Q

How can an object field be addressed?

A

let myObj =
{
make: “Buick”,
model: “Wildcat”,
}
console.log(myObj.make);