Strings, Arrays, and Object Methods Flashcards

1
Q

Strings:

Slice()
1. What does it manipulate(is it pure)?
2. Inputs?
3. Outputs?

syntax

A
  1. Does not modify the original string. pure
  2. method takes 2 parameters: start position, and end position (end not included).
  3. Extracts a section of a string and returns a new string. creates a new string

slice(start, end)

const str = '12 4567  910';

console.log(str.slice(0, 4));
// Expected output: "12 4"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

String

length

Its a property

exists on an instance of a string class

A
  • Doe not manipulate
  • property returns the length of a string
let  text = "ABCD";
let len = text.length
console.log(len)
// 4
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

String

includes()
  1. What does it manipulate(is it pure)?
  2. Inputs?
  3. Outputs?

Method

It is a case-sensitive method.

A
  • Pure
  • searchValue, start (defaults to 0)
    the position within the string at which to begin searching for (optional)
  • Boolean value

string.includes(searchvalue, start)

**NOTE: ** it will treat the Uppercase characters and Lowercase characters differently.

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

String

replace()
  1. What does it manipulate(is it pure)?
  2. Inputs?
  3. Outputs?

Method

A
  • does not mutate the original string. pure
    method replaces a specified value with another value in a string.
  • pattern (string), replacement (string or a function) called for each match
  • method returns a new string with one, some, or all matches of a pattern replaced by a replacement

replace(pattern, replacement)

the pattern can can also be a RegEx expression

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

string

subString()
  1. What does it manipulate(is it pure)?
  2. Inputs?
  3. Outputs?

Method

is similar to slice()

A
  • does not mutate the string. pure
  • extracts characters from indexStart up to but not including indexEnd.
  • A new string containing the specified part of the given string.
const str = 'Gozilla';
console.log(str.substring(1, 3));
// Expected output: "oz"

substring(start, end)

begins at a specified position, and returns a specified number of characters.

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

Strings

Bracket Notation
  1. What does it manipulate(is it pure)?
  2. Inputs?
  3. Outputs?

Special Syntax

Allows to access the individual characters that make up a string.

A
  • Does Nothing. property accesor, can extract string characters as read only by index
  • If no character is found, [ ] returns undefined.
    ~~~
    let text = “HELLO WORLD”;
    let char = text[0]; // H
    ~~~

syntax

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

String

How to loop over a string?

Iterator Method

A
const str = "abcdefu"'
for (let i = 0; i < str.length; i++) {
console.log(str[i]);
} // "a" "b" "c" "d" "e" "f" "u"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Strings

concat()
A
  • combines two or more arguments and returns a new srting
    ~~~
    const str = “cuoewcbeiyx”

console.log(str.concat(9));
console.log(str);

// cuoewcbeiyx9
// cuoewcbeiyx
~~~

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

Strings

template literals

Template Literals

string Interpolation

A
const firstName = "Shams"
const contex = " is challenging me"

console.log(`${firstName} ${context}`);
// expects: "Shams is challenging me"

synonyms

  • Template Literals
  • Template Strings
  • String Templates
  • Back-Tics Syntax
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

String

\+

Es5: “+”

A
const str1 = "wuuaao";
const str2 = ".....";
console.log(str1 + str2);

+ operaters works like concat() for strings

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

Strings

toUpperCase()
A

changes case sensitive string to Upper Case

const str = "i want to love you";
console.log(str.toUpperCase());
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

String

toLowerCase()

A

changes upper case charaters into case sensitive

const str = "I WANT TO GET THIS DONE Already!"

console.log(str.toLowerCase());
// expected: i want to get this done already!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

String

split()

Method

A

splits a string and returns a new array as substrings
* seperator and limit (if no parameter is placed it returns the string in the array)
~~~
const str = “I WANT TO GET THIS DONE Already!”

console.log(str.toLowerCase().split());
// [ ‘i want to get this done already!’ ]
~~~

const str = "I WANT TO GET THIS DONE Already!"

console.log(str.toLowerCase().split(" ", 5));
// [ 'i', 'want', 'to', 'get', 'this' ]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Arrays

forEach()

method

A
  • Iterates through arrays
  • takes any value and a function to manipulate the value
  • returns nothing, just iterates
const myBlessing = ["Shams", "is very lucky", "and so am I"];
//I: a function and string values
myBlessing.forEach((message) => {
    console.log(message);
}); //O: logs the Strings in the array

Shams
is very lucky
and so am I
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Arrays

map()
A
  • pure
  • Iterates through an array and returns a new array
  • callback function, @data type value, @index, and, @array

creates a new array with the results of calling a provided function on e

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

Arrays

filter()

method

A
  • pure, does not change the original array
  • callback function, this value
  • returns a new array filled with the elements that pass a test provided by a function

array.filter(function(currentValue, index, arr), thisValue)

17
Q

Arrays

concat()
A
18
Q

Arrays

Array.from()

static method

A

creates a new, shallow-copied Array instance from an iterable or array-like object.

19
Q

_.defaults(object, [sources])

A

Arguments:
* object (Object): The destination object.
* [sources] (…Object): The source objects.
Returns:
* (Object): Returns object.
Impure
mutates object.