Data Structures (Arrays and Objects) - Reading Assignment

Part 1

  1. The problem is how to store multiple bits of information which can be recalled or individually selected
  2. An array can be used to store many types of value
  3. A property is a characteristic of a value, for example length would be a property that returns a number indicating how long a value is.
  4. null and undefined are. 2 values that do not have any properties.
  5. Using dot notation or square brackets; i.e. value.x value[x]
  6. A method is an action that is particular to a value type, for example ‘push’ is a method that can be applied to an array to append an array value.
  7. Is it that an object is in simplest terms a group of things.
  8. An object is almost like a bunch of “and” conditions as things within the object all must be true else they would not be in the object. So they solve the need to write many and conditions.
  9. An object is a variable that is made up of group of things, which can if needed be individually altered - to change the objects group.
  10. JS objects appear to be highly mutable, you can change them as needed

Part 2

  1. String values are immutable hence new property request won’t work.
  2. Rest parameter, a different way of writing an array using the 3 dots. The benefit I can see of using it might be that you can combine two arrays to make 1, which can then be worked on. By 2 arrays I mean, some values can exist in the function pre the rest parameter, and the rest parameter values can be detailed when needed/called.
    3.skipped sub-chapter
  3. Serialization is a way of capturing values that were assigned to memory but now need to be transferred in some way
  4. JSON defines one format that is used to store serialises data and how to send it.
  5. With JSON you must use double quotes for property names, and 1 simple function can be used, and no comments.
1 Like

1. Read the sub-chapter called The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?
In this problem we need a variable type that can store multiple values.

2. What variable type can be used in order to solve the problem of storing multiple values?
An array is used to solve this type of problem.

3. What are properties in Javascript?
Properties are characteristics of values.

4. Which values do not have properties?
Null and Undefined

5. How can we access properties in a value (two ways)?
You can access properties by using . and [], each interpreted differently. . is looks at the literal name, [] is evaluated.

6. What are methods?
Properties that contain a function.

7. What are objects?
Objects are containers that contain a collection of properties.

8. What problem do objects solve that cannot be solved with other value types we’ve learned so far (such as integer, string, array, boolean etc)?
Objects can store multiple datatypes.

9. How do you define an object?
An object is defined by using the {} brackets. Example: var car = {model:“BMW”, color:“Blue”, year: 2000};

10. What can you say about the mutability of Javascript objects?
With mutability values can be changed, other types such as numbers and booleans are immutable and cannot.

SECOND PART:

1. Why can’t you add new properties to a string variable?
It is immutable.

2. What are rest parameters?
Rest parameters can be used to allow functions to accept any number of arguements.

3. (Feel free to skip the sub-chapter of Math object and Destructing)

4. What is serialisation and what is a use case of serialisation of data?
It is used to turn objects into a flat string, which helps compress the data and transfer it quicker.

5. What is JSON?
Javascript Object Notation

6. What are the differences between JSON and the way programmers write objects in plain Javascript?
They are very similar, but in JSON property names are surrounded by quotes, and only simple data expressions are allowed. You cannot use comments, function calls, or bindings.

1 Like
  1. It needs a data structure to store informations.
  2. Arrays.
  3. Properties are characteristics like length or max…
  4. Null and undefined.
  5. With a dot (value.x) or with square brackets (value[x]).
  6. Methods are properties that contain functions.
  7. Objects are arbitrary collections of properties.
  8. Objects can contain any different datatypes.
  9. let object1 = { left: 1, right: 2};
  10. You can change their properties, causing a single object value to have different content at different times.
    Second part:
  11. A string is immutable and it can’t be changed.
  12. The rest parameter syntax allows us to represent an indefinite number of arguments as an array.
  13. Serialize is a process that converted data into a flat description.
  14. JSON is JavaScript Object Notation.
  15. All property names have to be surrounded by double quotes, and only simple data expressions are allowed; no function calls, bindings, or anything that involves actual computation. Comments are not allowed in JSON.
1 Like

Hi @Yavuz_Gedik!

You’ve covered most of this well.
I can’t see your answer to Q6 of Part 2?

You’re half way there…here is the complete picture:

2 Likes

Hi @dAnijboned!

You’re progressing well :muscle:

Some really good answers to this (very) long exercise :sweat_smile:

Here are a couple of additional observations, to build on a couple of your answers:

Most values have properties, not just data structures. These properties are name/value pairs which store information about a value e.g. a string has a length property which stores as its value the number of characters in the string.

Yes you are right…to be even more specific, I would say that objects themselves are values that contain properties (name/value pairs).

1 Like
  1. we need to have a list of values but we don’t know which ones we will need on certain moment.
    2 Numbers, strings

  2. A characteristic of a value

  3. “Null”, “Undefined”
    5 Dot or square brackets

  4. A property that contain a function definition

  5. Value that contains properties(including functions)

  6. Unlike other value types, objects can contain multiple values and properties.

  7. By putting bracers inside of witch there are properties.

  8. Objects can be different even if they have the exact same number value.

  9. Values like string number and boolean. are immutable and can’t be changed. But they still have some built in properties.
    2 It’s a command that allows us to represent an indefinite number of arguments as an array.
    3 (Feel free to skip the sub-chapter of Math object and Destructing)

  10. Object serialization is the process of converting an object’s state to a string from which it can later be restored
    5.JavaScript Object Notation - is a lightweight data-interchange format

  11. A JSON objects contain data in the form of pair:
    “employee”: {
    “name”: “sonoo”,
    “salary”: 56000,
    “married”: true

Part 1
1, If you tried to use a string/integers, it is difficult to extract the digits and convert them back to numbers to access them.
2, An array.
3, Properties are the actual name of a value & belongs to an expression, eg, value[x] x is the property of a value named x.
4, Null and Undefined.
5, myString.length + Math.max
6, Properties that contain functions
7, Arbitrary collections of properties
8, Allows you to store a list of activities and a boolean value thereby including the functionality of a number and string as a single value grouped in an array of log entries.
9, By using braces as an expression, eg, after the start of a statement. Note: it is rarely useful to start a statement with an object in braces.
10, Unlike types of values such as numbers, strings or booleans which are all immutable ie, not able to be changed, objects work differently & their properties can be changed.

Part 2
1, Because it has an immutable value already and cannot be changed.
2, Functions that accept any number of arguments.
4+5, Converting data into a ‘flat description’ such as the JSON format(Java Script Object Notation) used for data storage + communication on the web.
6, JSON must use double quotes for all property names, only simple data expressions are allowed - no function calls, bindings or computation.

1 Like

1. Read the sub-chapter called The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?

  • The problems introduced in this chapter are Storing Sequences of Values and working with chunks of Digital Data.

2. What variable type can be used in order to solve the problem of storing multiple values?

  • The Array and Object variable

3. What are properties in Javascript?

  • A JavaScript property is a characteristic of a value, often describing attributes associated with a data structure.

4. Which values do not have properties?

  • Null and Undefined.

5. How can we access properties in a value (two ways)?

  • value.x and value[x]

6. What are methods?

  • Properties that contain functions are generally called methods of the value they belong to.

7. What are objects?

  • A JavaScript object is a collection of named values.

8. What problem do objects solve that cannot be solved with other value types we’ve learned so far (such as integer, string, array, boolean etc)?

  • Object tie different properties together to express a single condition. This allows programmers to better represent how a system should behave;
  • Objects are special as they are able to hold as many different datatypes as we need.

9. How do you define an object?

  • var person = {name: “Andrei”, age: 32};

10. What can you say about the mutability of Javascript objects?

  • Objects are mutable: They are addressed by reference, not by value;

  • If person is an object, the following statement will not create a copy of person:
    var x = person; // This will not create a copy of person.

  • The object x is not a copy of person. It is person. Both x and person are the same object. Any changes to x will also change person, because x and person are the same object.

  • Example:

    var person = {firstName:“John”, lastName:“Doe”, age:50, eyeColor:“blue”}

    var x = person;
    x.age = 10; // This will change both x.age and person.age

  • https://www.w3schools.com/js/tryit.asp?filename=tryjs_object_mutable


    SECOND PART:

1. Why can’t you add new properties to a string variable?

  • Because of strings are Immutable.

2. What are rest parameters?

3. (Feel free to skip the sub-chapter of Math object and Destructing)
:partying_face:

4. What is serialisation and what is a use case of serialisation of data?

  • Converts data into a flat description.

5. What is JSON?

6. What are the differences between JSON and the way programmers write objects in plain Javascript?

As the book says:

  • JSON looks similar to JavaScript’s way of writing arrays and objects, with a
    few restrictions. All property names have to be surrounded by double quotes,
    and only simple data expressions are allowed—no function calls, bindings, or
    anything that involves actual computation. Comments are not allowed in
    JSON.

  • A journal entry might look like this when represented as JSON data:
    {
    “squirrel”: false,
    “events”: [“work”, “touched tree”, “pizza”, “running”]
    }

1 Like
  1. The weresquirrel needed a data structure that was capable of holding multiple values.

  2. Arrays can be used to store multiple values.

  3. Properties are some further sub-category of information on a certain value.

  4. The only values without properties are null & undefined.

  5. Often accessed by a “.” separating the value and the property. Also sometimes accessed by value[property].

  6. Methods is the name given to properties that contain functions.

  7. Objects are arbitrary collections of properties.

  8. Objects are able to hold values of many different types at once.

  9. Objects are defined by using braces. The property will have a name: value.

  10. Javascript objects are mutable. Unlike numbers, strings, or booleans, they can change their values. The same value can have multiple different contents at different times.

  11. String variables are not classified as objects so they can not take on properties.

  12. Rest parameters are dictated by three dots before the last parameter and are useful in calling a function with multiple parameters.

  13. Skipped

  14. Serialisation allows the data to be converted to flat description. Serialisation allows for arrays inside other arrays to be transferred together to another computer or saved for later without having to save your entire computers memory.

  15. JSON is a very common Serialisation format which stands for JavaScript Object Notation.

  16. All properties have to be surrounded by double quotes. Also, in JSON, there can not be any computation performed…it must be simple data expressions.

2 Likes

Hi @Stas_Simon,

Most answers :ok_hand:

But here are some observations to help clarify the others:

Not really…

The problems that cannot be solved with primitive data types, such as strings or numbers, are:
(a) how to record and store multiple sets of related data (different conditions on different days, and whether or not he changed into a squirrel); and
(b) how to record and store this data in such a way that it can be effectively manipulated and analysed, in order to discover relationships and find out which conditions cause the transformation.
In other words…we need data structures.

No…

Arrays can be used to store multiple related values.

Sort of…

Separate objects are always unequal to each other, even if they have exactly the same properties with the same values.
This is because, unlike other values, the property values of JavaScript objects (including arrays) can be modified, whole properties deleted, and new properties added.

Yes, but so do objects in plain JavaScript. The question asks for the differences:

The way objects are written in JSON and plain JavaScript is largely the same, except that in JSON:
(i) all property names must be written within double quotes;
(ii) double quotes must be used for all string values (i.e. no option to use single quotes);
(iii) no functions/methods are allowed; and
(iv) no comments are allowed.

I hope that helps clarify things for you.

1 Like

Excellent answer sir! really well documented! keep it like that please! :muscle:

Carlos Z.

  1. Read the sub-chapter called The weresquirrel. What problems does this chapter introduce that cannot be solved with variable types such as strings or integers?

He needs a data structure to store this information.

  1. What variable type can be used in order to solve the problem of storing multiple values?

Arrays and Objects.
List of values between square brackets, separated by commas.

  1. What are properties in Javascript?

Properties are expressions that access the values inside an array. (i.e. myString.length)

  1. Which values do not have properties?

null and undefined
If you try to access a property on one of these nonvalues, you get an error.

null.length;
// → TypeError: null has no properties
  1. How can we access properties in a value (two ways)?

Dot or Sqaurebracket

value.x 
value[x]
  1. What are methods?

The push method adds values to the end of an array, and the pop method
does the opposite, removing the last value in the array and returning it.

  1. What are objects?

Objects are values of arbitrary collections of properties. You may think of objects as octopuses with any number of tentacles, each of which has a name tattooed on it.

let anObject = {left: 1, right: 2};
console.log(anObject.left);
// → 1
delete anObject.left;
console.log(anObject.left);
// → undefined
console.log("left" in anObject);
// → false
console.log("right" in anObject);
// → true
  1. What problem do objects solve that cannot be solved with other value types we’ve learned so far (such as integer, string, array, boolean etc)?

Arrays, then, are just a kind of object specialized for storing sequences of
things. If you evaluate typeof [], it produces “object”. You can see them as
long, flat octopuses with all their tentacles in a neat row, labeled with numbers.

  1. How do you define an object?

its like you define a variable but inside a {} separated by commas ,
For example:

let objectA = {a: 1, b: 2};
  1. What can you say about the mutability of Javascript objects?

Numbers, strings, and Booleans, are all immutable
Arrays are Immutable.

  1. Why can’t you add new properties to a string variable?

Because strings are immutable… See no.10

  1. What are rest parameters?
    Rest parameter is bound to an array containing all further arguments.
    Square bracket array notation similarly allows the triple-dot operator to
    spread another array into the new array.
let words = ["never", "fully"];
console.log(["will", ...words, "understand"]);
// → ["will", "never", "fully", "understand
  1. (Feel free to skip the sub-chapter of Math object and Destructing)
    :heart_eyes:

  2. What is serialisation and what is a use case of serialisation of data?

When data is converted into a flat description.

  1. What is JSON?

A popular serialization format is called JSON (pronounced “Jason”), which stands for JavaScript Object Notation. It is widely used as a data storage and communication format on the Web, even in languages other than JavaScript. JSON looks similar to JavaScript’s way of writing arrays and objects, with a few restrictions. All property names have to be surrounded by double quotes, and only simple data expressions are allowed

What are the differences between JSON and the way programmers write objects in plain Javascript?

JSON looks similar to JavaScript’s way of writing arrays and objects, with a few restrictions. All property names have to be surrounded by double quotes, and only simple data expressions are allowed

1 Like

Excellent answer sir! really well documented! keep it like that please! :muscle:

Carlos Z.

Part I

  1. Collecting values over time in a single data structure.
  2. An array can be used.
  3. A property is a handle which belongs to an object.
  4. null and undefined do not have properties
  5. x.property and x[“property”]
  6. A method is a property of type function.
  7. An object is a collection of properties.
  8. isn’t an array an object?
  9. For example: let obj = { prop1: “val1”, prop2: [1,2,3] }
  10. Objects are mutable, they can be changed (unlike numbers and strings)

Part II

  1. A string is immutable.
  2. Rest parameters refers to an arbitrary number of parameters that can be passed by using the …param notation)
  3. Serialization means gathering the data related to an object and putting into a nice sequence.
  4. JSON is a serialization standard for Javascript.
  5. JSON property names must be in quotes, and values have to be values (no bindings).
1 Like

Thank you very much Carlos! :star_struck:

Kind regards,
Andrei

1 Like

Yes, it can be an object.

If you have any doubt, please let us know so we can help you! :slight_smile:

Carlos Z.

2 Likes

It can be an object? So some arrays are objects and others are not? (I am asking because question 8 implies that arrays are not objects).

1 Like
  1. For this problem, storage of larger quantities of data must be created.
  2. Arrays
  3. Properties in JavaScript define characteristics of a value. For example: .length is used to define the length of a string.
  4. Null and undefined.
  5. It can be used by using a dot as in “x.length” and it can also be used by writing x[“length”].
  6. A method is a property that contains function values. They only work for the value that they belong to
  7. An object is a structure of data. Inside an object, the user can store different value types.
  8. They are unique in a way where they are able to hold as many different datatypes that is needed.
  9. An object is defined just like any other variable, with its value being a list within braces.
  10. The values they contain can be changed.

Second part:

  1. Because the string variables are immutable.
  2. They are parameters that are bound to an array.
  3. Serialization is flattening of the data description.
  4. JSON is a popular serialization format.
  5. In JSON you wrap keys and values with double quotes and can’t define methods.
1 Like

//part 1

  1. keeping data of irregular occurrences in a structural way
  2. array
  3. property is an object that contain a specific function to create values
  4. null and undefined
  5. two main way to access properties in JavaScript are with a dot and with square bracket ; value. x / value[x]
  6. properties that contain function
  7. arbitrary collection of properties
  8. flexible properties binding
  9. typeof [ ]
  10. amazing, make it easier to compile values of object

//part 2

  1. because string variable are immutable
  2. its a method of function to accept any number of arguments
    3.//skip
  3. serialisation is a concept of flat description, converting data storage and communication format on the WEB, like JSON for JavaScript Object Notation, and also other language
  4. JSON is JavaScript Object Notation
  5. all property names have to be surrounded by double quotes, and only simple data expression are allowed - no function caals, bindings, or anythings that involves actual computation
1 Like

Hi @letscrypto,

Yes, I agree with you that the way Q8 uses the terms object and array is a bit confusing…

Objects allow related data of different types (including further sub-sets of data within nested objects or arrays) to be grouped and stored together under one roof in a single value.

This is also essentially true of arrays, because all arrays are objects — a special type of object whose property “names” (keys) are all integers (indices) not strings. Arrays are indexed sequences of values (often of the same type, but not always), whereas “standard” objects have property names that can be any string, and which therefore:
(i) do not imply any particular sequence to the object’s values; and also
(ii) make “standard” objects better suited to recording, storing and manipulating related data of different value types.

So, personally, I think what Q8 is asking about is the benefits of {objects} compared to all other data types including array [objects] .

I hope that clears up the confusion, but just let us know if you have any further questions :slightly_smiling_face:

2 Likes