Skip to content

Instantly share code, notes, and snippets.

View Shariar-Hasan's full-sized avatar
😎
Chill

Shariar Hasan Shariar-Hasan

😎
Chill
View GitHub Profile
@Shariar-Hasan
Shariar-Hasan / primeOrNot.js
Created January 20, 2021 17:15
Finding prime number using Javascript function
function isPrime(num)
{
for (var i = 2; i<num ; i++)
{
if(num%i == 0)
{
return num+" is not a prime number";
}
}
return num+" in a prime number";
@Shariar-Hasan
Shariar-Hasan / fibonacciUsingRecursion.js
Last active September 7, 2023 21:59
Print n-th value of fibonaci series or Print the whole fibonacci series til n-th value using recursive function in Javascript
// if you want whole fibonacci series till n
let fibb = [0, 1];
function fibonacciTillN(n) {
if (fibb[n - 1] != undefined) {
return fibb[n - 1];
} else {
return (fibb[n - 1] = fibonacciTillN(n - 1) + fibonacciTillN(n - 2));
}
}
fibonacciTillN(10);
@Shariar-Hasan
Shariar-Hasan / fibonacciUsingLoop.js
Last active January 20, 2021 18:16
Print n-th value of fibonaci series or Print the whole fibonacci series til n-th value using loop in Javascript
// if you want the whole series of fibonacci
var fib = [0, 1];
var n = 10; // you can change this value
if (n == 1 || n == 2) {
console.log(fib);
}
else {
for (var i = 2; i < n; i++) {
fib.push(fib[i-1]+fib[i-2]);
@Shariar-Hasan
Shariar-Hasan / duplicateRemover.js
Created January 20, 2021 18:15
To remove duplicate items from an array in javascript
var numbers = [1,2,5,3,7,5,6,8,9,9,0,3,4,5,6,5,5,4,3,3,4,4];
function duplicateRemover(numbers)
{
var uniqueArray = []
for(var i = 0; i< numbers.length ; i++)
{
if(uniqueArray.indexOf(numbers[i]) == -1)
{
uniqueArray.push(numbers[i]);
@Shariar-Hasan
Shariar-Hasan / swapTwoNumbers.js
Created January 20, 2021 18:17
Swapping two number in javascript (3 methods)
// how to swap two variable
//*************** * way -1****************
var a = 5;
var b = 7;
console.log("brfore swap a = ",a,"and b =",b);
@Shariar-Hasan
Shariar-Hasan / wordCount.js
Last active September 7, 2023 21:37
counting words from a string in Javascript
var words = "amake amar moto thakte dao. ami nijeke nijer moto ghuchiye niyechi";
var counter=0;
for (var i = 0; i< words.length ; i++)
{
if(words[i] == " " && words[i-1] != " " && i != 0 && i != words.length-1)
{
counter++;
}
}
@Shariar-Hasan
Shariar-Hasan / stringReverse.js
Created January 20, 2021 18:20
two way to reverse a string in Javascript
// using a loop
var str = "i am a javascript programmer";
var reverseString = ""
for(var i = str.length ; i > 0; i--)
{
reverseString += str[i-1];
}
console.log(reverseString);
@Shariar-Hasan
Shariar-Hasan / randomGenerator.js
Last active September 7, 2023 21:32
random number generate (with + without) range in javascript
// how to create random numbers
// random numbers
var rand = Math.random(); //will create random number between 0 - 1
console.log(rand);
@Shariar-Hasan
Shariar-Hasan / map-filter-find.js
Created February 2, 2021 14:41
use of map,filter,find methods in array
let numbers = [1,2,3,4,5,6,7,8,9,10];
let result1 = numbers.map( (x) => x*10 );
console.log(result1);
let result2 = numbers.filter( (x) => x%2 ); //returns all values that meet the condition
console.log(result2);
@Shariar-Hasan
Shariar-Hasan / randNumGen.js
Created February 2, 2021 14:50
random number generator using function both string and number
// genarate random number with specific digit using function
function randNumber(n){
return Math.floor((Math.random()*10**n)); //if you want n digit random number as a number
}
function randNumString(n){
return (Math.random()*10**n+" ").split('.')[0]; //if you want n digit random number as a string
}