Skip to content

Instantly share code, notes, and snippets.

@FarhanMS123
Last active January 23, 2023 10:08
Show Gist options
  • Select an option

  • Save FarhanMS123/e752010feac2bfa31e39ff1d24e1b467 to your computer and use it in GitHub Desktop.

Select an option

Save FarhanMS123/e752010feac2bfa31e39ff1d24e1b467 to your computer and use it in GitHub Desktop.
A bundle of alrogithm and concepts.

Algorithm

List of Algorithm

  1. Range
  2. JS Notes

convert function to string via

function(){}.toString() or String(function(){})

convert it back to Function via

Function("function(){}")

there is a code such us this one :

var x = function(){}; x.a = "sample 1"; x.b = "sample 2";

it will become :

{[Function], a:"sample 1", b:"sample 2"}

you can get the Function via String(x);

"arguments" variable in function is to get an arguments from calling a function

function x(a,b,c){console.log(arguments)}
x("123", "abc", 555);

output : Arguments : ["123", "abc", 555]

function y(){console.log(arguments)}
y("123", "abc", 555);

output : Arguments : ["123", "abc", 555]

function.apply(null, []) is for call an arguments.

function x(a,b,c){console.log(`a:${a} || b:${b}`)}
x.apply(null, ["123", "abc", 555]);

output : a:123 || b:abc

function x(){console.log(arguments)}
x.apply(null, ["123", "abc", 555]);

output : Arguments[3] : ["123", "abc", 555];

Range is a way to decision a z-point from a-point to the b-point.
Example, we have 2 points. Point 20 and Point 70.
They have point from 20, 21, 22, 23, ..., 67, 68, 69, 70.
And not only that. They can have decimal value too,
such as 21.17453324, 21.17453325, 21.17453326, and so on.

so how we can got the x-point from 2 points?
like get percent value, it will solve with math.
lets say, we have 4 value. a, b, x, and v.
with a=20, b=70, x=100, and v=60.
a is the first value, b is the last value, x is the range from a to b, v is the point where we get, z is the point what we get.
in math, I use :
a + v(b-a)/x = z
why? when we want to get b from a, we should add a to (b-a) times v/x. if v same as x, then v/x= 1. so a+(b-a) = b.

  1. ok lets we begin we the sample where v = 100; 20 + (70-20)100/100=20+50=70
  2. v = 60 20 + (70-20)60/100=20 + (50)60/100=50
  3. v = 40 20 + (70-20)40/100=20 + (50)40/100=40
  4. v=50 20 + (70-20)50/100=20 + (50)50/100=45

Got it?
Well the function for now is

a + v(b-a)/x = z

so thank you for read this ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment