0% found this document useful (0 votes)
2 views4 pages

Js Code

The document contains various JavaScript functions demonstrating common programming tasks such as reversing a string, finding the longest word in a sentence, checking for palindromes, implementing a FizzBuzz program, filtering even numbers, swapping two numbers, removing duplicates from an array, checking for prime numbers, counting vowels, finding the largest number in an array, and summing elements of an array.

Uploaded by

palkhushboo204
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Js Code

The document contains various JavaScript functions demonstrating common programming tasks such as reversing a string, finding the longest word in a sentence, checking for palindromes, implementing a FizzBuzz program, filtering even numbers, swapping two numbers, removing duplicates from an array, checking for prime numbers, counting vowels, finding the largest number in an array, and summing elements of an array.

Uploaded by

palkhushboo204
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//!

Reverse the function

// function Reverse (str){

// return [Link]("").reverse().join("");

// }

// [Link](Reverse('khushi'))

//! Longest word in the sentense

// function Longestword(Name){

// return [Link](" ").reduce((longest, current)=>

// [Link] > [Link] ? current : longest

// );

// }

// [Link](Longestword(" hello my name is khushboo"))

//! string Palindrome or not

// function Palindrome(palin){

// const reverseStr = [Link]("").reverse().join("");

// return palin === reverseStr

// }

// [Link](Palindrome("khushi"))

// ! fizz-buss program

// for (let i=1; i<=100; i++)

// {

// if(i%3===0 && i%5===0)


// {

// [Link]("Fizz-buzz")

// }

// else if (i%3===0) {

// [Link]("fizz")

// }

// else if (i%5===0) {

// [Link]("buzz")

// }

// else{

// [Link](i)

// }

// }

// !even number

// let num=[1,2,3,5,7,14,57,45,87,64]

// let even=[Link](number=>number%2===0)

// [Link](even)

// !swaping of the two number

// let a=20 ,b=30;

// a=a+b;

// b=a-b;

// a=a-b;

// [Link]("a= "+a);

// [Link]("b= "+b);

// !Remove the duplicate item from an array


// let a=[2,3,2,5,3,6,7,6,5,8,9,7]

// let uniquArray = [...new Set(a)]

// [Link](uniquArray)

// !Prime number

// function isPrime(num){

// if(num<=1) return false;

// for(let i=2;i<num; i++)

// {

// if(num%i===0){

// return false

// }

// }

// return true

// }

// [Link](isPrime(12))

// [Link](isPrime(7))

// [Link](isPrime(8))

// [Link](isPrime(13))

// ! Count vowels

// function CountVowels(str){

// let count = 0;

// const vowels ="aeiou";

// for(let char of [Link]()){

// if([Link](char)){

// count++;
// }

// }

// return count;

// }

// [Link](CountVowels("khushI"));

// ! largest number

// function max(arr){

// return [Link](...arr);

// }

// [Link](max([3,56,48,39,3]));

// ! sum of array

// function sum(arr){

// return [Link]((num1,num2)=>num1+num2,0);

// }

// [Link](sum([2,4,1,0,4]));

You might also like