Algorithms

Preventing Data From Mutation with Freeze Method (javascript mutation)

In JavaScript, we declare variables with CONST when we want to protect it from mutation. But CONST declaration alone is not enough to protect really. Firstly let's see data protection with CONST: https://gist.github.com/muum/b82a71bd38e1749373d8646f299b55f4 As you see there is an alternative way to mutate CONST data. So what about if you really wat your data to be frozen? https://gist.github.com/muum/e24f72d10279893607c4bd420dcab86e You can use Object.freeze for arrays but ES5 can freeze only objects and throws an error. ES6 enables to freeze non-objects, too. Freeze method also blocks push, pop, shift and unshift methods 🙂

Read More

Murat Umutlu

0 Comment
Algorithms

Easy Way of Finding Max Element of an Array

Until 2015 we need apply method to apply Math.max function to all elements of an array. ES6 destructing feature, announced at 2015, gives us an unpacked version of an array so that it makes using "apply" unnecessary. https://gist.github.com/muum/5f67fc2e0ff4455c187d482bfc026503

Read More

Murat Umutlu

0 Comment
Algorithms

Finding Factorial of a Number with JavaScript

First of all we must understand the meaning of factorial: The factorial function multiply all numbers from our chosen number down to 1. For instance: 3! = 3 x 2! = 3 x 2 x 1 = 65! = 5 x 4! = 5 x 4 x 3 x 2 x 1 = 1201! = 10! = 1 Way of thinking: We need a recursive function to calculate multiply of ordered numbers.We must return 1 when we get 0 and we must stop recursive function. https://gist.github.com/muum/73aa06d9f063718a8a05ec27c4b0e3b9

Read More

Murat Umutlu

0 Comment
NodeJS

How to Hide API Keys of Your JavaScript Projects?

While developing SPA project, we sometimes need to use API keys. Although it is possible to hide these API keys with .ENV file importing method, you must find another method on production process because of the fact that: .env files’ content are visible to client when they investigate your .js files..env importing is used for when you want to hide api key on Github 🙂 Quick fix for this problem: You can try to create a new express.js project to get request from your client then forward this request this to 3rd party endpoint with API key (on backend side). After it gets response from 3rd party endpoint, your express.js backend project must forward this response to you. Here you can find my solution and steps: We integrate express pack (npm install express)Install helmet pack for possible security problems (npm install helmet)Use axios for get and post steps (npm install axios) https://gist.github.com/muum/c650ceba0a5cb32a1999b8a2ef841d73

Read More

Murat Umutlu

0 Comment
(Visited 35 times, 1 visits today)
Close