we can do it in this following way using reduce -- > function generateHash(str){ if(!str.trim().length || str.length>=280){ return false; } const res = str.trim().split(" ").reduce((acc,elem)=>{ return acc+elem.replace(elem.charAt(0),elem.charAt(0).toUpperCase()); },"#"); return res; } console.log(generateHash("try programiz"));
Hey I done this in Java Code by myself without watching Full Video And i successfully done it i am going to follow this whole series Thanks (◔◡◔) Also One suggestion I want like you give us Next challenge in this video i mean we try Day-3 by self so just give problem of next day at each previous day
Just in case someone is looking for an example using reduce: const generateHashTag = (sentence) => { let sentenceArr = sentence.split(" "); const hashTag = sentenceArr.reduce((acc, currElem) => { acc += currElem .slice(0, 1) .toUpperCase() .concat(currElem.slice(1, currElem.length)); return acc; }, "#");
//? Question: //? You are required to implement a function generateHash that generates a hash tag from a given input string. The hash tag should be constructed as follows: //? The input string should be converted to a hash tag format, where each word is capitalized and concatenated together without spaces. //? If the length of the input string is greater than 250 characters or if the input string is empty or contains only whitespace, the function should return false. //? Otherwise, the function should return the generated hash tag prefixed with #. //* Solution: function generateHash(str) { if (str.length > 250 && !str.trim()) return false; const words = str.split(" "); const capitalizedWords = words.map( (word) => word[0].toUpperCase() + word.slice(1) ); return `#${capitalizedWords.join("")}`; } console.log(generateHash("diwash bhattarai"));
function generateHash(str) { if (str.trim("") === "" || str.length > 280) { return false; }
const words = str.split(" "); let hashTagWord = "#"; for(let word of words){ word = word[0].toUpperCase() + word.slice(1,word.length); hashTagWord+=word; } return hashTagWord; } let result = generateHash("Hello this is manoj"); console.log(result);
Thapa bhai, mujhe js ka theoretical knowledge poora hai . Per mere logic + projects nahi banre hai. Like kaise kya likhu samajh nahi aata. Iska kuch upaaye hai to zarur bata dete to kaafi acha rheta. Bohot struggle Karra hu logic banane me🙏
Solved with for loop const str="i am software developer"; function temp(userStr){ const splittedStr=userStr.split(" "); let convertedStr=''; for(let i=0;i
This is the another way , const generateHash = (str) =>{ if(str.length>28 || str.trim().length ===0){ return false; } let stArr = str.split(" "); let modifiedArr = stArr.map((curElem)=>{ return curElem.charAt(0).toUpperCase() + curElem.slice(1); }) let newStr = modifiedArr.join('').replace(/,/g, '').replace('','#'); return newStr; } generateHash('i am Piyush mourya');
#MySolution : const generateHash = (str) => { if (str.trim().length > 280 || str.trim().length === 0) { return false; } //? making the array out of it let arrOfStr = str.split(' '); //? adding the hash tag let hashTag = '#' for (let index = 0; index < arrOfStr.length; index++) { hashTag = hashTag + arrOfStr[index][0].toUpperCase() + arrOfStr[index].substring(1); } return hashTag; }
I used the reduce method and also employed a new logic, such as substring, and concatenated within the loop using the + operator. 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞: 2/100 𝐂𝐨𝐦𝐩𝐥𝐞𝐭𝐞𝐝 Here is the Code: /* *STATEMENT: Problem: Hash Tag Generators *Example: 1] input: "my name is Vinayak" o/p: #myNameIsVinayak 2] input:"" o/p: false constraints: the length should not exceed 280Characters should not contain ONLY white spaces/ EMPTY if they contains both the above then return false */ function generateHashTags(str) { // remove the whitespaces if (str.trim().length === 0 || str.trim() > 280) { return false; } const strArray = str.trim().split(" "); // ******* Method-1 ******************** // const result = strArray.reduce( // (accm, currWord) => // (accm += currWord[0].toUpperCase() + currWord.substring(1)), //1 method, // // (accm += currWord.replace(currWord[0], currWord[0].toUpperCase())), // "" // ); // return `#${result}`; //*************************** */ // ******* Method-2******************** const result = strArray.map( (curWord) => // curWord.replace(curWord[0], curWord[0].toUpperCase()) // curWord.charAt(0).toUpperCase() + curWord.slice(1) curWord[0].toUpperCase() + curWord.substring(1) ); console.log(result); return `#${result.join("")}`; // *************************** } console.log(generateHashTags("I am vinayak kittad"));
function hashtagGen(sentence){ if(sentence.length>280 || sentence.trim().length===0){ return false } let words = sentence.replace(/\t/g, "").trim().split(" ")
// first method: // let CapitaliseWords = words.map((word)=>{ // return word.charAt(0).toUpperCase()+word.slice(1) // }) // let hashtagSentence = `#${CapitaliseWords.join("")}` // return hashtagSentence // 2nd method: let CapitaliseWords = words.map(word=>word.replace(word[0],word[0].toUpperCase())) return `#${CapitaliseWords.join("")}` } const res = hashtagGen("Don’t try to be over-smart with me") console.log(res)
function capitalizeWords(sentence) { return sentence.replace(/\b\w/g, char => char.toUpperCase()); } let sentence = "my name is vishal kushwaha"; let capitalizedSentence = capitalizeWords(sentence); let withoutwhitespace="#"+ capitalizedSentence.split(" ").join(""); console.log(withoutwhitespace);
function hashtag(string){ //if string length > 280 or itsa an empty or just space if(string.length > 280 || string.trim() === '' || string.length === 0){ return false; } else { /*removing trainl and end whitespace and making an array*/ let strArr = string.trim(' ').split(" "); /*Now iterating over each array and changing the first character to uppercase*/ let capitalArray = strArr.map((word)=>{ return word.charAt(0).toUpperCase() + word.slice(1); }); let hashtag = `#${capitalArray.join('')}` return hashtag } } let value = hashtag(" hi this is vikram bais "); console.log(value);
let generateHash = (str) => { if (str.length > 280 || str.trim().length === 0) { return false; } let x = str.split(" ") console.log(x) let y = x.map((e) => { return e[0].toLocaleUpperCase() + e.slice(1) }) console.log(y) let z = y.join("") console.log(z) let result = `#${z}` console.log(result) return result } console.log( generateHash("hello samyak") )
Hey I done this in Java Code by myself without watching Full Video And i successfully done it i am going to follow this whole series Thanks (◔◡◔) Also One suggestion I want like you give us Next challenge in this video i mean we try Day-3 by self so just give problem of next day at each previous day
Guy's hope you love the video❤ Plz LIKE SHARE & SUBSCRIBE NOW 😊
Javascript part 2 ky source code me Events wala folder missing hai Sir please upload it
We are loving it Sir.. keep going......!!!! 😊
My Solution
function generateHash(str){
if(str.length >= 280 || str.trim().length === 0){
return false
}
const strUpperCase = str.split(" ").map(curr => curr.charAt(0).toUpperCase() + curr.slice(1)).join("")
const hashStr = `#${strUpperCase}`
return hashStr
}
Thapa technical is the world best platform for coding learning
Ye Interview Questions series laake aapne bohot acha kiya.Naye Javascript sikhne waalo ka concept bohot clear ho jaayega.
Yes, I also want same
HTML CSS and JavaScript such mai world 🌍 best course ❤
we can do it in this following way using reduce -- >
function generateHash(str){
if(!str.trim().length || str.length>=280){
return false;
}
const res = str.trim().split(" ").reduce((acc,elem)=>{
return acc+elem.replace(elem.charAt(0),elem.charAt(0).toUpperCase());
},"#");
return res;
}
console.log(generateHash("try programiz"));
sister,how much time you give in the javascript???
Thanks Bhaiya, #2NdDayOfJavaScriptChallenge
Day 02 Present Sir . Love and Respect from Pakistan
const HashTagGenerator = (str) =>{
if(str.trim().length===0 || str.length>280){
return false;
}
const words = str.split(" ");
console.log(words);
let hashString="#";
for(let word of words){
hashString+=word.charAt(0).toUpperCase()+word.slice(1);
}
return hashString;
}
world best Html,Css , Javascript course 🎉❤
Hey I done this in Java Code by myself without watching Full Video And i successfully done it i am going to follow this whole series Thanks (◔◡◔)
Also One suggestion I want like you give us Next challenge in this video i mean we try Day-3 by self so just give problem of next day at each previous day
Sir i am watching your world best JavaScript course it is amazing i learned a lot ❤❤❤
my solution :
const Hashgenerator = (str) => {
if(str.length > 280 || str.trim().length {
return el = el.charAt(0).toUpperCase() + el.slice(1)
})
return str = "#"+str.join("")
}
const res = Hashgenerator("my name is sarthak vyas")
console.log(res)
great videos sir
Awesome
i do it with forEach loop
Great video😍😍😍😍😍😍😍
In the second solution, we can also use the rest operator for getting the remaining letters.
I don't know much javascript but I have good command on Java so I am solve these questions in java language 😅
Starting from Today.. Day 1
Day02 completed sucessfully🍀🍀
Thanks Bro..
1ch number thapa bhai❤
We are here in #Day-2
JavaScript Challenge 100/2 day is Completed 👍
❤❤😊 thanks sir
instead of slice we can use substring
const hashgenerator = (str)=>{
if(!str){return false}
if(str.length = 280){return false}
let arr = str.trim().split(" ")
arr = arr.map(item=>{
return item.slice(0,1).toUpperCase().concat(item.slice(1))
})
arr.unshift("#")
return arr.join("")
}
This Is what I want 10000000%
Just in case someone is looking for an example using reduce:
const generateHashTag = (sentence) => {
let sentenceArr = sentence.split(" ");
const hashTag = sentenceArr.reduce((acc, currElem) => {
acc += currElem
.slice(0, 1)
.toUpperCase()
.concat(currElem.slice(1, currElem.length));
return acc;
}, "#");
Love you ❤
MySolution
const generateHash = (str) => {
if (str.length > 280 || str.trim().length === 0) {
return false;
}
let resultString = "";
let words = str.split(" ");
words.forEach((element) => {
resultString += element[0].toUpperCase() + element.slice(1);
});
return "#" + resultString;
};
function genearetHashTag(string){
if(string.trim().length >= 280){
return false;
}
let arrayOfString = string.split(" ");
let prefix = "#";
for(let str of arrayOfString){
prefix+= (str.at(0).toUpperCase()+str.substr(1, str.length));
}
return prefix;
}
console.log(genearetHashTag("my name is anusuya bhattacharjee"))
//? Question:
//? You are required to implement a function generateHash that generates a hash tag from a given input string. The hash tag should be constructed as follows:
//? The input string should be converted to a hash tag format, where each word is capitalized and concatenated together without spaces.
//? If the length of the input string is greater than 250 characters or if the input string is empty or contains only whitespace, the function should return false.
//? Otherwise, the function should return the generated hash tag prefixed with #.
//* Solution:
function generateHash(str) {
if (str.length > 250 && !str.trim()) return false;
const words = str.split(" ");
const capitalizedWords = words.map(
(word) => word[0].toUpperCase() + word.slice(1)
);
return `#${capitalizedWords.join("")}`;
}
console.log(generateHash("diwash bhattarai"));
Sir please start the world best react native course
sir me 360p par dekha ta hu apka code isar acha nahi dikhata, can you plz change THEME , use font large
Hey, ThapaTechnical Sir, Please html5 canvas pay bhi koi video lay kar aoo.
🎉🎉🎉
Make video on php full course 2024
. Php is also important. 🙏
👍👍
function generateHash(str) {
if (str.length
increase the questions. 2 or 3 questions daily
#2
❤❤❤
function generateHash(str) {
if (str.trim("") === "" || str.length > 280) {
return false;
}
const words = str.split(" ");
let hashTagWord = "#";
for(let word of words){
word = word[0].toUpperCase() + word.slice(1,word.length);
hashTagWord+=word;
}
return hashTagWord;
}
let result = generateHash("Hello this is manoj");
console.log(result);
if it is possible so ,....please solve 3-4 question in single video
substring ka use krke :i-
const hashconvert = (name)=>{
if(name.length>280 || name.trim() === ""){
return false;
}
else{
const arr = name.split(" ");
const fres = arr.map((e)=>{
return e[0].toUpperCase() + e.substring(1);
})
return `#${fres.join("")}`
}
}
console.log(hashconvert("my name"))
Thapa bhai, mujhe js ka theoretical knowledge poora hai . Per mere logic + projects nahi banre hai. Like kaise kya likhu samajh nahi aata. Iska kuch upaaye hai to zarur bata dete to kaafi acha rheta. Bohot struggle Karra hu logic banane me🙏
Sir, What's the font style of your VS code ?
why dont you use Capitalize method
🙂👍
Solved with for loop
const str="i am software developer";
function temp(userStr){
const splittedStr=userStr.split(" ");
let convertedStr='';
for(let i=0;i
JavaScript Files Adhuri Send Huwi Hai Plz Complete Send Kijiye
Day #2 attendee 👩💻
Thapa sir firsr comment like my comment
Meno to dono q krr dia khud se
SIR PLZ BOOTSTRAP P VIDEO BANAEN
This is the another way ,
const generateHash = (str) =>{
if(str.length>28 || str.trim().length ===0){
return false;
}
let stArr = str.split(" ");
let modifiedArr = stArr.map((curElem)=>{
return curElem.charAt(0).toUpperCase() + curElem.slice(1);
})
let newStr = modifiedArr.join('').replace(/,/g, '').replace('','#');
return newStr;
}
generateHash('i am Piyush mourya');
#MySolution :
const generateHash = (str) => {
if (str.trim().length > 280 || str.trim().length === 0) {
return false;
}
//? making the array out of it
let arrOfStr = str.split(' ');
//? adding the hash tag
let hashTag = '#'
for (let index = 0; index < arrOfStr.length; index++) {
hashTag = hashTag + arrOfStr[index][0].toUpperCase() + arrOfStr[index].substring(1);
}
return hashTag;
}
I used the reduce method and also employed a new logic, such as substring, and concatenated within the loop using the + operator.
𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞: 2/100 𝐂𝐨𝐦𝐩𝐥𝐞𝐭𝐞𝐝
Here is the Code:
/*
*STATEMENT:
Problem: Hash Tag Generators
*Example:
1]
input: "my name is Vinayak"
o/p: #myNameIsVinayak
2]
input:""
o/p: false
constraints:
the length should not exceed 280Characters
should not contain ONLY white spaces/ EMPTY
if they contains both the above then return false
*/
function generateHashTags(str) {
// remove the whitespaces
if (str.trim().length === 0 || str.trim() > 280) {
return false;
}
const strArray = str.trim().split(" ");
// ******* Method-1 ********************
// const result = strArray.reduce(
// (accm, currWord) =>
// (accm += currWord[0].toUpperCase() + currWord.substring(1)), //1 method,
// // (accm += currWord.replace(currWord[0], currWord[0].toUpperCase())),
// ""
// );
// return `#${result}`;
//*************************** */
// ******* Method-2********************
const result = strArray.map(
(curWord) =>
// curWord.replace(curWord[0], curWord[0].toUpperCase())
// curWord.charAt(0).toUpperCase() + curWord.slice(1)
curWord[0].toUpperCase() + curWord.substring(1)
);
console.log(result);
return `#${result.join("")}`;
// ***************************
}
console.log(generateHashTags("I am vinayak kittad"));
function hashtagGen(sentence){
if(sentence.length>280 || sentence.trim().length===0){
return false
}
let words = sentence.replace(/\t/g, "").trim().split(" ")
// first method:
// let CapitaliseWords = words.map((word)=>{
// return word.charAt(0).toUpperCase()+word.slice(1)
// })
// let hashtagSentence = `#${CapitaliseWords.join("")}`
// return hashtagSentence
// 2nd method:
let CapitaliseWords = words.map(word=>word.replace(word[0],word[0].toUpperCase()))
return `#${CapitaliseWords.join("")}`
}
const res = hashtagGen("Don’t try to be over-smart with me")
console.log(res)
function Tags(str) {
if (str.length > 280 || str.trim().length === 0) {
return false;
}
let intoArray = str.split(" ");
let getFirstLetter = intoArray
.map((word) => word.toUpperCase().slice(0, 1) + word.slice(1))
.join("");
str = `#${getFirstLetter}`;
console.log(str);
}
Tags("hello world");
Tags("my name is khan");
function generateHash(str) {
if (str.trim().length === 0 || str.length > 180) {
return false;
}
const words = str.split(" ");
const capitalizedWords = words.map(word => word.charAt(0).toUpperCase() + word.slice(1));
let joinWords = capitalizedWords.join("");
let startWithHash = "#" + joinWords;
return startWithHash;
}
console.log(generateHash("my name is thapa technical"));
function capitalizeWords(sentence) {
return sentence.replace(/\b\w/g, char => char.toUpperCase());
}
let sentence = "my name is vishal kushwaha";
let capitalizedSentence = capitalizeWords(sentence);
let withoutwhitespace="#"+ capitalizedSentence.split(" ").join("");
console.log(withoutwhitespace);
function hasTag(str) {
let text = '';
let temp = [];
let strarr = str.split(" ");
if (str.trim().length > 280 || str.trim().length === 0) {
return false
} else {
for (let i = 0; i < strarr.length; i++) {
temp = strarr[i].split("");
temp[0] = temp[0].toUpperCase();
temp = temp.join("");
text += temp;
temp = [];
}
}
return (`#${text}`);
}
console.log(hasTag("this is a javascript"));
function generateHash(str) {
if (str.length > 200 || str.trim().length === 0 || str === " ") return false;
let words = str.split(" ");
let updatedWord = [];
for (word of words) {
word = word[0].toUpperCase() + word.slice(1);
updatedWord.push(word);
}
return `#${updatedWord.join("")}`;
}
function hashtag(string){
//if string length > 280 or itsa an empty or just space
if(string.length > 280 || string.trim() === '' || string.length === 0){
return false;
} else {
/*removing trainl and end whitespace and making an array*/
let strArr = string.trim(' ').split(" ");
/*Now iterating over each array and changing the first character to uppercase*/
let capitalArray = strArr.map((word)=>{
return word.charAt(0).toUpperCase() + word.slice(1);
});
let hashtag = `#${capitalArray.join('')}`
return hashtag
}
}
let value = hashtag(" hi this is vikram bais ");
console.log(value);
function hashGenerate(str){
if(str.length >= 280 || str.trim().length === 0){
return false
}
let newStr = str.split(" ")
let hashWord = ''
for(let i =0; i
const genratedHash = (hash)=>{
if(hash.length === 280 || hash.trim().length === 0){
return false;
}
let hashTag = hash.split(" ");
let str = "#";
for(let i = 0; i < hashTag.length; i++){
let one = hashTag[i];
let two = one[0].charAt(0).toUpperCase() + one.slice(1);
str += two;
}
return str;
}
console.log(genratedHash("my name is dilip"));
let generatehashValue = (str) => {
if (str.length > 250 || str.trim().length === 0) {
return false;
}
str = str.split(" ");
let eachWords = str.map((el) => {
return el.replace(el[0], el[0].toUpperCase());
});
const finalAns = [...eachWords];
finalAns.unshift("#");
console.log("Final String:", finalAns.join(""));
};
generatehashValue("csk forever");
let generateHash = (str) => {
if (str.length > 280 || str.trim().length === 0) {
return false;
}
let x = str.split(" ")
console.log(x)
let y = x.map((e) => {
return e[0].toLocaleUpperCase() + e.slice(1)
})
console.log(y)
let z = y.join("")
console.log(z)
let result = `#${z}`
console.log(result)
return result
}
console.log(
generateHash("hello samyak")
)
sister how much time you give in the javascript for a this stage??
const generateHash=(str)=>{
if(str.length > 200 || str.trim().length === 0){
return false
}
else{
}
var cheack = str.split(' ')
var result = []
for(i=0; cheack.length>i;i++){
var firstLetter = cheack[i][0].toUpperCase()
var restOfWrode = cheack[i].slice(1)
result.push (firstLetter+restOfWrode)
}
console.log(`#${result.join('')}`)
}
console.log(generateHash("Hello and welcome my name is Abdur Razzaque"));
const generateHash = (str) => {
if (str.length > 280 || str === '') return false;
const words = str.split(' ');
let newStr = '';
//* 1st
for (const word of words) newStr += word.charAt(0).toUpperCase() + word.slice(1);
//* 2nd
newStr = words.map(word => word.replace(word[0], word[0].toUpperCase())).join('');
return newStr ? '#' + newStr : false;
};
const word = generateHash('The quick brown fox jumped over the lazy dog');
console.log("🚀 ~ word:", word);
Hey I done this in Java Code by myself without watching Full Video And i successfully done it i am going to follow this whole series Thanks (◔◡◔)
Also One suggestion I want like you give us Next challenge in this video i mean we try Day-3 by self so just give problem of next day at each previous day
❤❤