let p= [‘a’,’a’, ‘g’, ‘f’, ‘b’,’z’,’y’,’c’,’t’ ,’s’,’x’,’x’,’n’];

var output =[],match=false;

for(var a =0;a < p.length;a++ ){
match=false;

for(var b=0; b<output.length ;b++){

if(output[b]===p[a]){
match=true;
}
}

if(!match){
output.push(p[a])
}

}

console.log(output)
console.log(“a”<”b”)

function getSort (x){

for(var b=1; b<x.length ;b++){
if(x[b-1]<x[b]){

}else{
let k = x[b];
x[b]=x[b-1]
x[b-1]=k
x= getSort (x)

}

}
return x
}
console.log(getSort(output))


Node.js is the JavaScript runtime environment that is based on Google’s V8 Engine i.e. with the help of Node.js we can run the JavaScript outside of the browser. Other things that you may or may not have read about Node.js is that it is single-threaded, based on event-driven architecture, and non-blocking based on the I/O model.

  1. Node.js Architecture: Node.js is made of Chrome V8 engine which is written in C++ and Libuv which is a multi-platform C library that provides support for asynchronous I/O based events on event loops and thread loops. Don’t worry it is explained in this later…

Closure means that an inner function always has access to the vars and parameters of its outer function, even after the outer function has returned.

function OuterFunction() {

var outerVariable = 1;

function InnerFunction() {
alert(outerVariable);
}

InnerFunction();
}

JavaScript Hoisting refers to the process whereby the interpreter allocates memory for variable and function declarations prior to execution of the code. Declarations that are made using var are initialized with a default value of undefined. Declarations made using let and const are not initialized as part of hoisting.


What are promises?

A Promise is an object, representing the eventual completion or failure of an asynchronous operation.

why?

createAudioFileAsync(audioSettings).then(successCallback, failureCallback);

One of the great things about using promises is chaining.

  • Multiple callbacks may be added by calling then() several times. They will be invoked one after another, in the order in which they were inserted.

Promise.all() and Promise.race() are two composition tools for running asynchronous operations in parallel.

Promise.all([func1(), func2(), func3()])
.then(([result1, result2, result3]) => { /* use result1, result2 and result3 */ });

const promise = new Promise(function(resolve, reject) {
console.log(“Promise callback”);
resolve();
}).then(function(result) {
console.log(“Promise callback (.then)”);
});

setTimeout(function() {
console.log(“event-loop cycle: Promise (fulfilled)”, promise)
}, 0);

console.log(“Promise (pending)”, promise);

output will be

“Promise callback”
“Promise (pending)”
[object Promise] { … }
“Promise callback (.then)”
“event-loop cycle: Promise (fulfilled)”
[object Promise] { … }


console.log(1)
setTimeout(()=>{ console.log(2) ;},0)
console.log(3)

the output will be

1,3,2


Arrow function expressions

An arrow function expression is a compact alternative to a traditional function expression, but is limited and can’t be used in all situations.

Differences & Limitations:


Declarative programming is a programming paradigm … that expresses the logic of a computation without describing its control flow.
Imperative programming is a programming paradigm that uses statements that change a program’s state.

Declarative Programming is like asking your friend to fix your car. You don’t care how to fix it, that’s up to her.

Imperative Programming is like your friend calling your father that tells her how to fix your car step by step.

Imperative code instructs JavaScript on how it should perform each step. With declarative code, we tell JavaScript what we want to be done, and let JavaScript take care of performing the steps.


function checkPalindrome(i){

let sum=0,r=0,n=i;

while(i>0){
r=i%10;
sum=sum*10+(r);

i=parseInt(i/10)
console.log(sum,r,i)
}
console.log(n,”===”,sum)
if(n===sum){
return “Palindrome number “
}else{
return “not Palindrome number “
}
}

// console.log(checkArmstrongNumber(407))

console.log(checkPalindrome(121))


function checkArmstrongNumber(i){

let sum=0,r=0,n=i;

while(i>0){
r=i%10;
sum=sum+(r*r*r);

i=parseInt(i/10)
console.log(sum,r,i)
}
console.log(n,”===”,sum)
if(n===sum){
return “armstrong number “
}else{
return “not armstrong number “
}
}

// console.log(checkArmstrongNumber(407))

console.log(checkArmstrongNumber(153))

Keshav Gautam

Javascript Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store