|
|
@ -53,35 +53,74 @@ console.log(itCompanies[0], itCompanies[Math.floor(itCompanies.length / 2)], itC
|
|
|
|
for(let i = 0; i < itCompanies.length; i++) console.log(itCompanies[i]);
|
|
|
|
for(let i = 0; i < itCompanies.length; i++) console.log(itCompanies[i]);
|
|
|
|
|
|
|
|
|
|
|
|
// 11. Change each company name to uppercase one by one and print them out
|
|
|
|
// 11. Change each company name to uppercase one by one and print them out
|
|
|
|
for(let i = 0; i < itCompanies.length; i++) {
|
|
|
|
const companies = [...itCompanies]
|
|
|
|
itCompanies[i] = itCompanies[i].toUpperCase()
|
|
|
|
console.log(companies)
|
|
|
|
console.log(itCompanies[i])
|
|
|
|
// for(let i = 0; i < itCompanies.length; i++) {
|
|
|
|
};
|
|
|
|
// itCompanies[i] = itCompanies[i].toUpperCase()
|
|
|
|
|
|
|
|
// console.log(itCompanies[i])
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
// 12. Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies.
|
|
|
|
// 12. Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies.
|
|
|
|
|
|
|
|
let sentence = '';
|
|
|
|
|
|
|
|
for(let i = 0; i < itCompanies.length; i++) {
|
|
|
|
|
|
|
|
if(i < itCompanies.length - 1) {
|
|
|
|
|
|
|
|
if(i == 5) {
|
|
|
|
|
|
|
|
sentence += `${itCompanies[i]} `
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sentence +=`${itCompanies[i]}, `
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sentence += `and ${itCompanies[i]} are big IT companies.`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(sentence)
|
|
|
|
|
|
|
|
|
|
|
|
// 13. Check if a certain company exists in the itCompanies array. If it exist return the company else return a company is not found
|
|
|
|
// 13. Check if a certain company exists in the itCompanies array. If it exist return the company else return a company is not found
|
|
|
|
|
|
|
|
const has = comp => {
|
|
|
|
|
|
|
|
if(itCompanies.includes(comp)) {
|
|
|
|
|
|
|
|
let company = itCompanies.indexOf(comp)
|
|
|
|
|
|
|
|
console.log(itCompanies[company])
|
|
|
|
|
|
|
|
return itCompanies[company]
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
console.log(`${comp} is not found.`)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
has('Facebook')
|
|
|
|
|
|
|
|
|
|
|
|
// 14. Filter out companies which have more than one 'o' without the filter method
|
|
|
|
// 14. Filter out companies which have more than one 'o' without the filter method
|
|
|
|
|
|
|
|
const lessThan2O = []
|
|
|
|
|
|
|
|
let count; let arr;
|
|
|
|
|
|
|
|
itCompanies.forEach((company) => {
|
|
|
|
|
|
|
|
arr = company.split('')
|
|
|
|
|
|
|
|
count = 0
|
|
|
|
|
|
|
|
for(let i = 0; i < company.length; i++) {
|
|
|
|
|
|
|
|
if(company.charAt(i) == 'o') {
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(count < 2) lessThan2O.push(company);
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(lessThan2O)
|
|
|
|
|
|
|
|
|
|
|
|
// 15. Sort the array using sort() method
|
|
|
|
// 15. Sort the array using sort() method
|
|
|
|
|
|
|
|
itCompanies.sort((a, b) => {
|
|
|
|
|
|
|
|
if(a < b) return -1
|
|
|
|
|
|
|
|
if(a > b) return 1
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log(itCompanies)
|
|
|
|
|
|
|
|
|
|
|
|
// 16. Reverse the array using reverse() method
|
|
|
|
// 16. Reverse the array using reverse() method
|
|
|
|
|
|
|
|
console.log(itCompanies.reverse())
|
|
|
|
|
|
|
|
|
|
|
|
// 17. Slice out the first 3 companies from the array
|
|
|
|
// 17. Slice out the first 3 companies from the array
|
|
|
|
|
|
|
|
console.log(itCompanies.slice(0, 3))
|
|
|
|
|
|
|
|
|
|
|
|
// 18. Slice out the last 3 companies from the array
|
|
|
|
// 18. Slice out the last 3 companies from the array
|
|
|
|
|
|
|
|
console.log(itCompanies.slice(itCompanies.length - 3, itCompanies.length))
|
|
|
|
|
|
|
|
|
|
|
|
// 19. Slice out the middle IT company or companies from the array
|
|
|
|
// 19. Slice out the middle IT company or companies from the array
|
|
|
|
|
|
|
|
console.log(itCompanies.slice(Math.floor(itCompanies.length / 2), Math.ceil(itCompanies.length / 2)))
|
|
|
|
|
|
|
|
|
|
|
|
// 20. Remove the first IT company from the array
|
|
|
|
// 20. Remove the first IT company from the array
|
|
|
|
|
|
|
|
|
|
|
|