This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
LEETCODE PROBLEM: 1678. Goal Parser Interpretation | |
You own a goal-parser that can interpret a string command. The command consists of an alphabet of "G", "()" and/or "(al)" in some order. The goal-parser will interpret "G" as the string "G", "()" as the string "o" and "(al)" as "al". The interpreted strings are then concatenated in the original order. | |
Given the string command, return the goal-parser's interpretation of command. | |
---------- | |
EXAMPLE 1: | |
---------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IMPORT AND INITIALIZE EXPRESS | |
var express = require ('express'); | |
const fetch = require('node-fetch'); | |
const socketIo = require('socket.io'); | |
var app = express(); | |
var port = 9000; | |
// CONNECT TO SOCKET IO | |
const server = app.listen(port); | |
const io = require('socket.io')(server); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react'; | |
import io from 'socket.io-client'; | |
const FeedSection = () => { | |
const socket = io("ws://localhost:9000"); | |
socket.on('latest_quakes', data => { | |
if (data) { | |
console.log(data); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// REGULAR FUNCTION DECLARATION | |
function my_cats(a,b,c) { | |
return `My cats names are: ${a}, ${b} & ${c}`; | |
} | |
my_cats('Tom', 'Marty', 'Jimmy'); | |
// ARROW FUNCTION | |
let my_cats = (a,b,c) => { | |
return `My cats names are: ${a}, ${b} & ${c}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SINGLE LINE ARROW FUNCTIONS WITHOUT RETURN KEYWORD OR {} | |
let oldest_cat = c => `${c} is the oldest one`; | |
oldest_cat('Jimmy'); // Jimmy is the oldest one |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//------------------------------------------------ | |
// COPY ELEMENTS FROM ONE ARRAY INTO ANOTHER ARRAY | |
//------------------------------------------------ | |
const fruits = ['apple', 'mangoe', 'papaya']; | |
const updated_fruits = ['banana', ...fruits]; | |
console.log(updated_fruits); // [ 'banana', 'apple', 'mangoe', 'papaya' ] | |
//------------------- | |
// MERGING TWO ARRAYS | |
//------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// OPTIONAL CHAINING EXAMPLE | |
let character = { | |
name: 'Dean Winchester', | |
age: 34, | |
car: 'Chevy Imala (Baby)', | |
enemy_demons: [ 'Abadon', 'Yellow Eyes', 'Crowley' ], | |
enemy_angels: [ 'Zacharia', 'Michael', 'Lucifer' ], | |
family: { | |
mother: 'Mary', | |
father: 'John', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let Dean = { | |
name: 'Dean Winchester', | |
age: 34, | |
car: 'Chevy Imala (Baby)', | |
enemy_demons: [ 'Abadon', 'Yellow Eyes', 'Crowley' ], | |
enemy_angels: [ 'Zacharia', 'Michael', 'Lucifer' ], | |
family: { | |
mother: 'Mary', | |
father: 'John', | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// REGULAR IF/ELSE | |
const cat_love_checker = (status) => { | |
if (status === false) { | |
return 'Sigh... my cat does not love me :('; | |
} else { | |
return 'Aha! My cat does love me!'; | |
} | |
} | |
cat_love_checker(false); // Sigh... my cat does not love me :( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// REGULAR WAY | |
let fav_num; | |
let fav_fruit = 'Apple'; | |
console.log(fav_num); // undefined | |
console.log(fav_fruit); // 'Apple' | |
// SHORTER WAY | |
let fav_num, fav_fruit = 'Banana'; |
OlderNewer