Skip to main content

Posts

[BAEKJOON Online Judge + Node.js] 2292: Honeycomb

  I did't use while loop that much so didn't come up what to do. While loop create a loop that execute a specific statement. So, the main point of this problem is "prevNum + max * 6" input = 13, output = 3 https://www.acmicpc.net/problem/2292 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while const input = require ( "fs" ). readFileSync ( "/dev/stdin" ). toString () ; let count = 1 ; let max = 1 ; // set the range while (max < input) { max += count * 6 ; count ++ ; } console . log (count) ; // prevNum + count * 6 // 1 so +6 every loop! // 2 - 7, 5 // 8 - 19, 11 // 20 - 37, 17 // 38 - 61, 23

29/06/2021 TIL

1. PS(BOJ/Programmers) update programmers questions on github  2. Project (DividendDB & OXINION) with JS/React Fundamental of JS course  3. CS for Interview summary interview questions 

Basic input and output of JavaScript(Node.js)

Groom(readline module) const input = require ( 'fs' ) . readFileSync ( '/dev/stdin' ) . toString ( ) . split ( '\n' ) ; BOJ(FS module) // Run by Node.js const readline = require ( "readline" ) ; const rl = readline . createInterface ( { input : process . stdin , output : process . stdout , } ) ; let input = [ ] ; rl . on ( "line" , function ( line ) { // let num = line.split(' ').map(Number); for one line input . push ( line . trim ( ) ) ; // rl.close(); } ) . on ( "close" , function ( ) { const length = parseInt ( input [ 0 ] ) ; const values = input [ 1 ] . split ( " " ) . map ( Number ) ; console . log ( `your length is ${ length } & your arr is ${ values } ` ) ; process . exit ( ) ; } ) ;

[BAEKJOON Online Judge + Node.js] 1181: Word sort

This is my first attempt  const input = require ( "fs" ). readFileSync ( "/dev/stdin" ). toString (). split ( " \n " ) ; const count = Number (input[ 0 ]) ; // 13 // 1. shortest word.length // 2. If the length is the same, in alphabetical order // sort() ? let newArr = [] ; // insert all elements in array let shortest = input[ 1 ]. length ; // just initial value for ( let i = 1 ; i <= count ; i ++ ) { newArr . push (input[i]) ; } // remove duplicated elements in array let removedArr = newArr . filter ( ( item , index ) => newArr . indexOf (item) === index) ; removedArr . sort ( ( a , b ) => { return a . length - b . length ; } ) ; console . log (removedArr) ; i cannot get the correct answer as my answer keeps mixing the order like  [  'i',  'no',  'it',  'im',  'but',  'wont',  'more',  'wait',  'yours', 'cannot',  'hesitate' ...

Basic input and output of JavaScript(Node.js)

Goorm (readline module) // Run by Node.js const readline = require ( "readline" ) ; const rl = readline . createInterface ( { input : process .stdin, output : process .stdout, } ) ; let input = [] ; rl . on ( "line" , function ( line ) {     // let num = line.split(' ').map(Number); for one line input . push ( line . trim ()) ; // rl.close(); } ). on ( "close" , function () { const length = parseInt (input[ 0 ]) ; const values = input[ 1 ]. split ( " " ). map ( Number ) ; console . log ( `your length is ${ length } & your arr is ${ values } ` ) ; process . exit () ; } ) ; BackJoon (fs module) let fs = require ( "fs" ) ; let input = fs . readFileSync ( "/dev/stdin" ). toString (). split ( " \n " ) ;

The Complete Guide React by Maximilian - #1 : Getting Started

7. About this course & course outline  Basics & Foundation of React (Introducing key features) Component & Building UIs Events & Data "props" and "state" Styling React Apps & components Styling React Apps & Hooks Advanced concepts   Side Effects. "Refs" & More React Hooks React Context API & Redux Forms HTTP Requests & "Custom Hooks" Routing, Deployment, NextJS & More Summaries & Refreshers  JS Refresher React Summary 

Forkify - Vanilla JS

282. Loading a Recipe from API async/fetch const   showRecipe   =   async   function  () {    try  {      renderSpinner ( recipeContainer );      // 1) Loading recipe      const   res   =   await   fetch (        'https://forkify-api.herokuapp.com/api/v2/recipes/5ed6604591c37cdc054bc886'     ); 283. Rendering the recipe  after making markup html code       recipeContainer . innerHTML   =   '' ;      recipeContainer . insertAdjacentHTML ( 'afterbegin' ,  markup ); 284. Listening for load and hashchange events dynamic id after removing '#' with slice(1)      const   id   =   window . location . hash . slice ( 1 );      renderSpinner ( recipeContainer );      //...

How to get Input case data in Node.JS

Every website provides a different skeleton code to start with.  BOJ const   input   =   require ( "fs" ). readFileSync ( "/dev/stdin" ). toString ( ' \n ' ); console . log ( input ); Programmers - just focus on the code itself, solution function for the logic function   solution ( numbers ) {      var   answer   =  [];      return   answer ; } Groom  const   readline   =   require ( "readline" ); const   rl   =   readline . createInterface ({    input :  process . stdin ,    output :  process . stdout , }); let   data   =  []; rl . on ( "line" ,  function  ( line ) {    data . push ( line );    //console.log(data);    data   =   line . split ( " " ). map (( el )  =>   el );    console . log ( data );    // data =...

JavaScript Patterns, including MVC

 JavaScript Patterns  1. Module & Revealing Module pattern  // STANDARD MODULE PATTERN - private/public variable const UICtrl = ( function () { let text = "Hello world" ; const changeText = function () { const element = document . querySelector ( "h1" ) ; element .textContent = text ; }; // public which is accessible from outside return { callChangeText : function () { changeText () ; console . log (text) ; } , }; } )() ; UICtrl . callChangeText () ; 2. Singleton pattern  it can only return one instance of an object at a time  3. Factory pattern Creating an interface for creating objects  MVC Pattern  It is consist of with following Model, View, Controller.  M odel take responsibility for data(application info) like data structure.  V iew represent for UI.  C ontroller is like a bridge between Model and View. They don't know each other. So it does monitor the change of Model ...

Frequency Counter example

function   validAnagram ( str1 ,  str2 ) {    // add whatever parameters you deem necessary - good luck!    if  ( str1 . length   !==   str2 . length ) {      return   false ;   }    const   lookup   =  {};    for  ( let   i   =   0 ;  i   <   str1 . length ;  i ++ ) {      let   letter   =   str1 [ i ];      lookup [ letter ]  ?  ( lookup [ letter ]  +=   1 )  :  ( lookup [ letter ]  =   1 );   }    console . log ( lookup );    for  ( let   j   =   0 ;  j   <   str2 . length ;  j ++ ) {      let   letter   =   str2 [ j ];      if  ( ! lookup [...