destruct_objts_dt Flashcards

1
Q

create a func that accepts a list. the func should pull items from the list which have a specified number of characters and
append the item to a new list. Then,return the new list.

A
function friend(friends){
  var realFriends = [];
  for(friends[i]= 0; i < friends.length; i++)
    if ( friends[ i ].length === 4 )
        realFriends.push ( friends[ i ])
  return realFriends
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can I get a obj. method. to return selected items from an array (from inside an obj) and destruct said items into berries? (return multiple (berried) values in a func) NOTE: func is nested

A
  1. order: function (starterIndex, mainIndex) {
    return [this.starterMenu[starterIndex], this.mainMenu[mainIndex]];},
  2. const [berry1, berry2] = obj.func(userInpu1, userInput2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can I unpack array items from an object and berry them at the same time?
What about if i wanna skip an item?

A

const [item1,item2] = obj.keyname

if I wanna skip, simply put a comma between the items in the berried array

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

unpack multiple array items into berries at same time:

A

unpack multiple array items into berries at same time:
create a berried array with muliple items. 2. create another array with berry names, replacing each item. The catch: write the array backwards, using the same berry name in the first array.

a = [,2,3,1]

[x,y,z] = a

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

How can i destruct a nested array: let arr = [4,2,[1,2]]

A

write it back wards. (i can skip items by writing a comma)

const [i, , [t,g]] = arr

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

for unknown arrays which i dont know the length, how do i set default values to items that may
not exist?

A

const [p = 1, q = 1, r = 1] = [8,9] (r is defaulted to 1, the others stay as 8 and 9)

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

to destruct objs we use {} braces. So , how can I destruct and berry up keys?

A

const {keyName, keyName1, etc…} = objName

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

Say that i destructed and berried up some keys. How can I change the berry names if i want?

A

create another berry-dict; put the original name followed by a colon, and then write the new name. after all the entries, put the equals sign and then the objName

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

How can i create a default key within an Obj. And, how can I change the name of a key if I want?

A

const { newKey = [ ], updatedKeyName: renamedKey} = obj

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

How can i over ride global berries and reassign them

to keys within an obj with the same berry-name?

A

put curly braces on the left side. Inside go al the berries. Then put the equal sign and the object name.
Next: wrap the entire expression in Evanders

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

How can I extract and berry-up objects within an object?

A

start with const. Then put curlies. The 1st nested object comes next. Then put a colon. Then write name of any other secondary nested objects, separated by a comma. then equals primary obj. I keep in mind that the primary obj. has been berried up beforehand.

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

Can I pass an object as a param in an object method? what would the method look like?

A

yes. I can pass the keys as parameters. The obj method may look something like this: methName: function (par, par1, par2) { CL( ${this.par[ par index ]}, ${this.par1[ par1 index]} etc )

Note: I call it from out side: MainObjName.method({ put entire dictionary here })

Note: dictionary names must match the param names in the method
Note: i can even set defaults in the params: par = ‘value’

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

How do I add items to an array: the old way and the new way?

A

old way: beryup a new array; add the new items and then add the original array items like:
original[ 0 ], original[ 1 ]: berry = [ 1, 2, 3, original[0 ] ]

new way: berry = [1, 2, . . .originalArray]

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

What prints when I print: CL(. . .myArray)

A

it unpacks array without evanders

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

How can i revise an existing property (which contains an array) with new values? (w/o changing original property)

A

const newProp = [. . .MainObj.propToUpdate, ‘ newValue’ ]

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

How can I copy an array within an obj?

A

const myCopyArr = [. . .mainObj.prop]

17
Q

How can i merge 2 arrays?

A

const merged = [. . .arr1 , . . .arr2]

18
Q

How can i print individual elements of a str?

A

const myCommaSeparatedStr = [. . .str, ‘add if i want’]

19
Q

What are the 2 situations in where i use the spread op?

A
  1. when building an array 2. when passing values into a func.
20
Q

I can use the spread op. to copy an obj. and add properties? How?

A

const objCopy = {. . .OriginalObjName , founder: ‘ jo ‘}