JSFiddle - React, Tailwind, and code Playground

by Sunny SM

JavaScript

/* GIVE STRING IS PALIDROME OR NOT */
const isPalidrome = (name) => {
	if (name) {
  	const temp = name.split('').reverse().join('');
    if (temp === name) {
    	return 'Given string is palidrom';
    } else {
    	return 'Given string is not palidrom';
    }
  }
}
console.log('Is Palidrome : ', isPalidrome('love'));

/* SUM OF ARRAY LIST */
const getTotal = (a, v) => a + v;
const scoreList = [10,1,15,14,10];
console.log('Sum of Array List : ', scoreList.reduce(getTotal));

/* COMBINE TWO LIST BY ALTERNATIVILY EACH ELEMENTS */
const combineLists = (list_1, list_2) => {
	const result = [];
  const start = 0;
  let end = list_1.length;
  if (list_1.length < list_2.length) {
  	end = list_2.length;
  }
  
  for(let i = start; i < end; i++) {
  	if (list_1[i]) {
    	result.push(list_1[i]);
    }
  	if (list_2[i]) {
    	result.push(list_2[i]);
    }
  }
  return result;
}
const list1 = [1,2,3,4,5];
const list2 = ['A', 'B', 'C', 'D'];
console.log('Combined list is : ', combineLists(list1, list2));

/* FUNCTION THAT TAKE NUMBER AND RETUREN ITS DIGIT LIST */
const numberToDigitList = (num) => num.toString().split('');
console.log('Number digit list id : ', numberToDigitList(45850));

/* FUNTION TWO SWAP TWO NUM WITH 3RD VAR */
const swapNumber = () => {
	let a = 10;
  let b = 15;
	console.log(`Before Swap A is : ${a} and B is : ${b}`);
  a = a + b;
  b = a - b;
  a = a - b;
  console.log(`After Swap A is : ${a} and B is : ${b}`);
}
swapNumber();
/*RAISE POER OF GIVEN NUMBER*/
const getGivenNumberMul = (a, b) => {
	let result = 0;
	for(let i = 1; i < b; i++) {
  	const temp = a * i;
    result = temp * a;
  }
  return result;
}
console.log('Raise Power is : ', getGivenNumberMul(5, 2));

/*RAISE POER OF GIVEN NUMBER WITHOUT MUL*/
const getGivenNumberWMul = (a, b) => Math.pow(a, b);
console.log('Raise Power is : ', getGivenNumberWMul(5, 3));

/*FIND 2nd LARGEST NUMBER IN ARRAY*/
const bigestNumber = () => {
  const num = [2, 5, 8, 1, 4];
  const temp = num.sort();
 ...