Day 51: fibonacci, JSON

Inseo Park·2021년 9월 9일
0

Path to Data Scientist

목록 보기
49/58
post-thumbnail

1. TIL (Today I Learned)

fibonacci

Return the number of the nth term in the Fibonacci sequence defined as below.

The 0th Fibonacci number is 0, and the 1st Fibonacci number is 1. After the second Fibonacci number, it is defined as the sum of the two immediately preceding Fibonacci numbers. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...

function fibonacci(n) {
const memo = [0, 1];
const aux = (n) => {
  if (memo[n] !== undefined){
    return memo[n];
  } memo[n] = aux(n - 1) + aux(n - 2);
  return memo[n]
}
return aux(n);
}

JSON

Achievement Goals

  • Understand that the JSON structure is a tree structure that can use recursive functions (stringifyJSON).
  • Understand that JSON.stringify and JSON.parse are serialize and deserialize.
  • You can use JSON.stringify and JSON.parse to pass between JavaScript values & JSON.
  • When using recursive calls with JSON, you can understand where to use them.

The Birth of JSON

JSON is an abbreviation for JavaScript Object Notation, which is an object format created for data exchange. Suppose you want to send the contents of an object to another program, over a network.
If the contents of this object are a message used in a messenger or chat program, how can the enxt object be transmitted.

const message = {
  sender: "김코딩",
  receiver: "박해커",
  message: "해커야 오늘 저녁 같이 먹을래?",
  createdAt: "2021-01-12 10:10:10"
  }

In order for a message object to be transmitttable, the sender & receiver of the message must use the same program or have a universally readble form such as a string.

transferable condition:

  • the receiver & sender use the same program
  • OR, it should be universally readable like a string.

Objects do not contain object contents when converted to string using type conversion. When you try a method (message.toString()) or (String(message)) on an object in JavaScript, the result is [object Object].

The way to solve this problem is to convert the object to the form of JSON or convert the JSOn to form of the object.
The method for this is:

JSON.stringify = Converts object type to JSON.
JSON.parse = Conver JSON to Object type.

let transferable Message = JSON.stringify(message)
console.log(transferableMessage) // '{"sender":"김코딩","receiver":"박해커","message":"해커야 오늘 저녁 같이 먹을래?","createdAt":"2021-01-12 10:10:10"}'
console.log(typeof(transferableMessage)) // 'string'

This process of stringifying is called serializing.

The type of object converted to JSON is string. The sender can send the object's content to someone with a serialized string of the object. So how can the receiver recreate this string message in the form of an object? You can use the method JSON.parse which does the opposit of JSON.stringify.

let obj = JSON.parse(transferableMessage)
console.log(obj) // {sender: '김코딩', receiver: '박해커', message: '해커야 오늘 저녁 같이 먹을래?', createdAt: '2021-01-12 10:10:10'}
console.log(typeof(obj)) // 'object'

The process of applying JSON.parse is called deserializing.

As sch, JSON is a format for exchanging data between different programs. JSON format is a popular format that is universally used in many languages, including JavaScript.

2. 3 Things to be Thankful for

  1. Thank God for protecting me from the shooting drill.
  2. Thank God for allowing my Dad to celebrate a good birthday.
  3. Thank God for helping me overcome the fear of not being able to learn coding or data science by relying on your plan.

3. Ideas and Things to think about.

  1. God has plans for you already, no matter you are good or bad at what you are doing now it is all up to him so please stay happy and just enjoy the lessons in life. Don't do anything that you don't feel happy to do so.
profile
my journey to become a data scientist.

1개의 댓글

comment-user-thumbnail
2024년 2월 1일

Now there are many ways and solutions that will allow you to increase the security and reliability of your data. The JSON programming language will be no exception to this. Click this link to learn more about JSON, the different software you can use to work with the language, and read a short tutorial on using the JSON to String Converter.

답글 달기