more on funcs, arrays,bind,CB, forEach,map(),filter,reduce,DOM Flashcards

1
Q

how can i bind a param to a func? and wha t is the point of binding a func?

A
create a funcparam
now create a binded func:
let bound = OGfuncName.bind(null, prevalent value)

note: i set null because in this case the “this” keyword isnt used
2. binding a func is usefull if a have a certain param that is used frequently!

basically im creating a new func just for a special param

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

provide an example on a CB func that acts like a bind func.

A
  1. create an OGfunc with a param
  2. return the CB with a parm
  3. RETURN the expression
  4. berryup the OGfunc with a param
  5. func the berry and paramize it; then call it
const taxRater = function (rate) {
  return function (value) {
    return value * rate + value; }; };
const getTax = taxRater(0.1);
console.log(getTax(200));
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how can bind be useful with objts? describe an example.

A

Bind can be useful if a have abunch of objts that require the same method:

const myMethod = ogMethod.bind(otherObj)
myMethod( otherParam, otherParam1)

NOTE: Console.log(otherOBJ) to see the results

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

Why is bind useful with eventHandlers? describe what an event handler function loos like?

A

the handler func “this” keyword always points to the html element, not the obj we want.
Fix:
document.querySelector(‘btn-name’).addEventListener(‘click’, obj.method.bind( obj )

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

arr = [1,2,3,4,5]
what does: arr.splice(1, 2) prnt?

why is slice cool?

A

[1, 4, 5]

It is good for deleting unwanted items. especially the last item

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

how can i get the last item of an array?

can i use at with strs?

A

arr. at( -1 )

yessir: CL(‘jonas’.at( 0 )

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

what old fashion method does the forEach() replace?

give an example please.

A

it replaces the for loop if/else block.

let x = array.forEach(function(item, i, array) {
        return (expression) } )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can i upload a list child element to a webpage?

A

(container name) which is…..

doc.QS-tag berry.insertAdjacentHTML(‘afterbegin’, htmlStringBerry)

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

How can i delete container elements from a webpage?

A

container name.innerHTML = ‘ ‘;

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

What does map( ) do? Provide an example.

A

map method creates a new array with items that have undergone an operation. Its a CB func.

const newArr = oldArr.map(function(item, i, array) {
        return item * usdToEuroBerry} )

this returns a new array with all items updated according to the operation specified.

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

what does filter do? Example plz.

A

filter method revises an array based on a condition

const positiveNums = +&-Array.filter(function(item, i ) {
       return item > 0 } )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

describe the “creating a username forEach method” that jonas taught you.

we are cycling an array of objs and adding a prop to each obj in the array

A

const createUser = function(accs) {

accs. forEach(function(acc ) {
     accs. username = accs.owner.toLowerCase( ).split(' ').map( name => name[ 0 ].join()

createUser( arrayOfaccountObjs)

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

what does the reduce method do? example plz

A

reduce method boils all items in an array down to one value via the snowball accumulator:

const x = array.reduce(function(acc, item, i, array) {
    return acc + cur}, 0 );

this gives the sum of all numbers. NOTE: remember the accumulator start point parameter

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