Git Product home page Git Product logo

Comments (17)

hafsamubarak avatar hafsamubarak commented on August 28, 2024 1

I have a problem with Exercise level1 number 14: I don't know how to filter the array to print the companies that have more than 'o'?!

from 30-days-of-javascript.

devprotim avatar devprotim commented on August 28, 2024 1

I have a problem with Exercise level1 number 14: I don't know how to filter the array to print the companies that have more than 'o'?!

I had the same issue, thanks for asking.

from 30-days-of-javascript.

Tejas9535 avatar Tejas9535 commented on August 28, 2024 1

I have a problem with Exercise level1 number 14: I don't know how to filter the array to print the companies that have more than 'o'?!
if you don't get the condition you can also use =>
element.includes('oo')
solution =>

itCompanies.forEach(element => { console.log(element); console.log(!/(.).\1/.test(element)); if (/(o).\1/.test(element)) { console.log(${element} contains more than one 'O'); } else { console.log(${element} doesn't contain more than one 'O'); } });

can you pls explain the code Tejas?

This is a regex expression and it checks whether there is more than or 2 'o' in each element you can also use element.includes('oo') this condition will work too. It will check element of thes includes two 'o's.

from 30-days-of-javascript.

devprotim avatar devprotim commented on August 28, 2024 1

My soliution which was gitving undefined i have fixed it => const even= countries.length % 2 === 0 const len= Math.round(countries.length/2) if (even) { console.log(countries[len - 1], countries[len]) } else { console.log(countries[len]) }

IMO this one's accurate:

console.log(countries.length)
const even= countries.length % 2 === 0
const len= Math.round(countries.length/2)
if (even) {
console.log( countries[len])
} else {
console.log(countries[len - 1])
}

from 30-days-of-javascript.

devprotim avatar devprotim commented on August 28, 2024 1

alright, pls post the solution if you solve it

from 30-days-of-javascript.

Tejas9535 avatar Tejas9535 commented on August 28, 2024

which question are talking about ?

from 30-days-of-javascript.

devmaier avatar devmaier commented on August 28, 2024

Level 3: Find the middle country(ies) in the [countries array]

from 30-days-of-javascript.

Tejas9535 avatar Tejas9535 commented on August 28, 2024

why would you need avarage word lenght and all that.
solution-1
You can just =>
check if the array is odd or even
const even= countries % 2 === 0
const len= countries.lenght
if (even) {
console.log(countries[len/2], countries[len/2 + 1])
} else {
console.log(countries[len + 1/2])
}

Do tell me if you find any better solution!!!!!!

from 30-days-of-javascript.

devmaier avatar devmaier commented on August 28, 2024

solution-2
I think the correct solution would be:
// ---------- Number of letters in country name ---------- //
for (let i = 0; i < countries.length; i++) {
countries[i] = countries[i].length
}
console.log(countries)

// ------ Finding the maximum, minimum and arithmetic mean ------ //
function findMax(array) {
return Math.max.apply(null, array);
}
function findMin(array) {
return Math.min.apply(null, array);
}
console.log(findMax(countries), findMin(countries));
average = (findMax(countries) + findMin(countries)) / 2
console.log(average);

// ------ Search for the arithmetic mean ------ //
let findAverage = countries.indexOf(average)
console.log(findAverage);

I don't understand how to sort correctly. two indexes 45 and 182 should appear. Then you need to bring them to a string. This is what I still can't figure out how to do.
Indeed, in the task it is indicated to find the middle country in the array. And not the average length of the array....

from 30-days-of-javascript.

Tejas9535 avatar Tejas9535 commented on August 28, 2024

My soliution which was gitving undefined i have fixed it =>
const even= countries.length % 2 === 0
const len= Math.round(countries.length/2)
if (even) {
console.log(countries[len - 1], countries[len])
} else {
console.log(countries[len])
}

from 30-days-of-javascript.

Tejas9535 avatar Tejas9535 commented on August 28, 2024

solution-2 I think the correct solution would be: // ---------- Number of letters in country name ---------- // for (let i = 0; i < countries.length; i++) { countries[i] = countries[i].length } console.log(countries)

// ------ Finding the maximum, minimum and arithmetic mean ------ // function findMax(array) { return Math.max.apply(null, array); } function findMin(array) { return Math.min.apply(null, array); } console.log(findMax(countries), findMin(countries)); average = (findMax(countries) + findMin(countries)) / 2 console.log(average);

// ------ Search for the arithmetic mean ------ // let findAverage = countries.indexOf(average) console.log(findAverage);

I don't understand how to sort correctly. two indexes 45 and 182 should appear. Then you need to bring them to a string. This is what I still can't figure out how to do. Indeed, in the task it is indicated to find the middle country in the array. And not the average length of the array....

and in this one You can round up findAverage using Math.round() of Math.floor() but it will stop at first index .

Regarding your method i'm not sure if you are trying to find the arithmatic min

Still I think this will give you the index of middle element = >
let totalEle = null
countries.forEach(element => {
totalEle =+ element
});
let mean = Math.round((totalEle/countries.length) * 10)
let middleEle = countries[mean]
console.log(Math.round(mean));
console.log(middleEle);

from 30-days-of-javascript.

Tejas9535 avatar Tejas9535 commented on August 28, 2024

I have a problem with Exercise level1 number 14: I don't know how to filter the array to print the companies that have more than 'o'?!
if you don't get the condition you can also use =>
element.includes('oo')
solution =>

itCompanies.forEach(element => {
console.log(element);
console.log(!/(.).\1/.test(element));
if (/(o).
\1/.test(element)) {
console.log(${element} contains more than one 'O');
} else {
console.log(${element} doesn't contain more than one 'O');
}
});

from 30-days-of-javascript.

devprotim avatar devprotim commented on August 28, 2024

I have a problem with Exercise level1 number 14: I don't know how to filter the array to print the companies that have more than 'o'?!
if you don't get the condition you can also use =>
element.includes('oo')
solution =>

itCompanies.forEach(element => { console.log(element); console.log(!/(.).\1/.test(element)); if (/(o).\1/.test(element)) { console.log(${element} contains more than one 'O'); } else { console.log(${element} doesn't contain more than one 'O'); } });

can you pls explain the code Tejas?

from 30-days-of-javascript.

devprotim avatar devprotim commented on August 28, 2024

itCompanies.forEach(element => {
console.log(element);
console.log(!/(.).\1/.test(element)); if (/(o).\1/.test(element)) {
console.log(${element} contains more than one 'O');
} else {
console.log(${element} doesn't contain more than one 'O');
}
});

Im getting this output:

HTML
true
HTML doesn't contain more than one 'O'
CSS
true
CSS doesn't contain more than one 'O'
JavaScript
false
JavaScript doesn't contain more than one 'O'
React
true
React doesn't contain more than one 'O'
Redux
true
Redux doesn't contain more than one 'O'

true
MongoDB
true
MongoDB doesn't contain more than one 'O'

Using this arr=

const webTechs = [
'HTML',
'CSS',
'JavaScript',
'React',
'Redux',
'Node',
'MongoDB'
]

from 30-days-of-javascript.

Tejas9535 avatar Tejas9535 commented on August 28, 2024

itCompanies.forEach(element => {
console.log(element);
console.log(!/(.).\1/.test(element)); if (/(o).\1/.test(element)) {
console.log(${element} contains more than one 'O');
} else {
console.log(${element} doesn't contain more than one 'O');
}
});

Im getting this output:

HTML true HTML doesn't contain more than one 'O' CSS true CSS doesn't contain more than one 'O' JavaScript false JavaScript doesn't contain more than one 'O' React true React doesn't contain more than one 'O' Redux true Redux doesn't contain more than one 'O'

true MongoDB true MongoDB doesn't contain more than one 'O'

Using this arr=

const webTechs = [ 'HTML', 'CSS', 'JavaScript', 'React', 'Redux', 'Node', 'MongoDB' ]

Aah seems you have found a bug in my code as it will only count two consecutive 'o' but if there are two 'o' and they have any alphabet between them it won't check.I'll have to check it again.

from 30-days-of-javascript.

stallion10 avatar stallion10 commented on August 28, 2024

any who can help me with this solution

First remove all the punctuations and change the string to array and count the number of words in the array

let text =
'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.'
console.log(words)
console.log(words.length)
["I", "love", "teaching", "and", "empowering", "people", "I", "teach", "HTML", "CSS", "JS", "React", "Python"]

13

from 30-days-of-javascript.

Tobcrown avatar Tobcrown commented on August 28, 2024

2.3: Reversing an array.
1 def reverse(A):
2 N = len(A)
3 for i in xrange(N // 2):
4 k = N - i - 1
5 A[i], A[k] = A[k], A[i]
6 return A
Python is a very rich language and provides many built-in functions and methods. It turns
out, that there is already a built-in method reverse, that solves this exercise. Using such a
method, array A can be reversed simply by:
1 A.reverse

from 30-days-of-javascript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.