NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

function findLongestWord(str) {
var strSplit = str.split(" ");

var longestWord = strSplit.sort(function (a, b) {
return b.length - a.length;
});

return longestWord[0];
}

console.log(findLongestWord("The quick brown fox jumped over the lazy dog"));
/*---------------------------------------------------------------------------------
OTHER WAY TO FIND LONGEST STRING
[NOTE] :- DON'T REMOVE SPACE AFTER THAT CAPTIAL Z BECAUSE WE INCLUDE SPACE ALSO....

*/
function LongestWord(str) {
return str
.replace(/[^a-zA-Z ]/g, "")
.split(" ")
.reduce((a, b) => (a.length > b.length ? a : b));
}

LongestWord("The quick brown@ fox jumped123 over the lazy dog ");

//-------------------------------------------------------------------------------

//remove repeating element from array.
/*
Syntax:-
array.filter(function(currentValue, index, arr), thisValue)

Parameter Description
function() Required.
A function to run for each array element.

currentValue Required.
The value of the current element.

index Optional.
The index of the current element.

arr Optional.
The array of the current element.

thisValue Optional. Default undefined
A value passed to the function as its this value.


*/
let chars = ["A", "B", "A", "C", "B"];

let uniqueChars = chars.filter((c, index) => {
return chars.indexOf(c) === index;
});

console.log(uniqueChars);

//using for each

let chars2 = ["A", "B", "A", "C", "B"];

let uniqueChars2 = [];
chars2.forEach((c) => {
if (!uniqueChars2.includes(c)) {
uniqueChars2.push(c);
}
});

console.log(uniqueChars2);

// get duplicate elements from the arrry. just reverse the condition of above condition.
//-- filter thi duplicate remove karya aeni condition reverse karvani

let dupChars = chars.filter((c, index) => {
return chars.indexOf(c) !== index;
});

console.log(dupChars);

/*
zero to hero - folder 9 video number 15th
we have now 4 datastructue in js

array
object
set -new
map -new

set:- set contains only uniue elements in their list..
let's do all operation that can be perform on set.
*/

let colors = ["red", "yellow", "green", "red"];

let colorset = new Set(colors);
console.log(colorset); //Set(3) { 'red', 'yellow', 'green' }

console.log(colorset.has("black")); // false
console.log(colorset.has("red")); // true

colorset.add("white");
console.log(colorset); //Set(4) { 'red', 'yellow', 'green', 'white' }

colorset.delete("white");
console.log(colorset); //Set(3) { 'red', 'yellow', 'green' }

for (let color of colorset) console.log(color);

//example how to remove repeating elements from array using set and then conver set into array.

let colors2 = ["red", "yellow", "green", "red"];

uniquecolors = [...new Set(colors2)]; //convert set to array.
console.log(uniquecolors); //[ 'red', 'yellow', 'green' ]

console.log(uniquecolors.length);

//convert to camelcase in js.

let str = "some_name";

const [first, second] = str.split("_");
const output = `${first}${second.replace(second[0], second[0].toUpperCase())}`;

console.log(output);

//=================================================================

const str1 = "abcdefgh";
const str2 = "gedcf";
const subIncludesAll = (str1, str2) => {
for (let i = 0; i < str1.length; i++) {
if (str2.indexOf(str1[i]) !== -1) {
str2 = str2.replace(str1[i], "");
}
}
return str2.length === 0;
};

const minWindow = (str1 = "", str2 = "") => {
let shortestString = null;
for (let i = 0; i < str1.length; i++) {
for (let j = i; j < str1.length; j++) {
let testString = str1.substr(i, j - i + 1);
if (subIncludesAll(testString, str2)) {
console.log(str2);
console.log("aa", subIncludesAll("abcdefg", str2));
}
}
}
};
console.log(minWindow(str1, str2));

//====================================================================

function QuestionsMarks(str) {
var matches = str.match(/d[w?]*?d/g);
if (!matches) return false;

var result = false;

for (var match of matches) {
if (Number(match[0]) + Number(match[match.length - 1]) === 10) {
// count the numbers of ?'s in the substring between two numbers
if (match.split("").filter((char) => char === "?").length === 3) {
result = true;
} else {
return false;
}
}
}

return result;
}
===============================file 2 ===========================ds_code
//String Reverse

function reverse(str) {
return console.log(str.split("").reverse().join(""));
}

reverse("Hello My Nams Is Dhruvin");

// Merge sorted
//.sort() function is basically used for string sorting..
// so do number sorting we have to add compare function to the sort function.. to more information how sort() work. read below document.
//https://www.w3schools.com/jsref/jsref_sort.asp

function mergeSortedArray(...a) {
let b = [...a].flat().sort(function (a, b) {
return a - b;
});
console.log(b);
}

mergeSortedArray([1, 3, 10, 5], [7, 4, 6, 50], [2, 8, 9]);

//another best way ....
function mergeSortedArrays(...arrays) {
return arrays
.reduce((previousValue, currentValue) =>
previousValue.concat(currentValue)
)
.sort(function (a, b) {
return a - b;
});
}

console.log(
mergeSortedArrays([33, 46, 61, 130], [], [3, 4, 6, 30], [13, 24, 16, 30])
);

//Find First Recursion from array..

function firstRecurringCharacter2(input) {
var numbers2 = [];
for (i = 0; i < input.length; i++) {
if (numbers2.indexOf(input[i]) === -1) {
numbers2.push(input[i]);
} else {
console.log(input[i]);
break;
}
}
}
// firstRecurringCharacter2([2, 5, 5, 2, 3, 5, 1, 2, 4]);

const recur = function (arr) {
let number2 = [];
for (let [i, e] of arr.entries()) {
if (number2.indexOf(arr[i]) === -1) {
number2.push(arr[i]);
} else {
console.log(arr[i]);
break;
}
}
};

// recur([2, 5, 2, 2, 3, 5, 1, 2, 4]);

function number(n) {
if(n>1){
return n ** 2 + number(n-1);
}
else{
return 1
}
}

console.log(number(3));

===================================================practice
const getData = async function()
{
const users = await fetch('https://jsonplaceholder.typicode.com/users');
let data = await users.json();
console.log(data);
//Leanne Graham
let replace = JSON.stringify(data);
// console.log(replace)

const final_data = data.filter((e,index) => {
if(e.name.includes('Leanne Graham'))
{
return data[index];
}
return
})
console.log(final_data)
}

// getData();


let myObj = { name: "John", age: 31, city: "New York" };
let myJSON = JSON.stringify(myObj);
localStorage.setItem("testJSON", myJSON);

let text = localStorage.getItem("testJSON");
let obj = JSON.parse(text);
console.log(obj)


     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.