30-Days-Of-JavaScript
30-Days-Of-JavaScript copied to clipboard
Day6: Exercise2: problem 6:
I get confused with this question I know it's so easy but I cannot write the exact syntax for it
@devprotim I think you're answering another question The question I talk about is to print array of arrays like this: [ ['Albania', 'ALB', 7], ['Bolivia', 'BOL', 7], ['Canada', 'CAN', 6], ['Denmark', 'DEN', 7], ['Ethiopia', 'ETH', 8], ['Finland', 'FIN', 7], ['Germany', 'GER', 7], ['Hungary', 'HUN', 7], ['Ireland', 'IRE', 7], ['Iceland', 'ICE', 7], ['Japan', 'JAP', 5], ['Kenya', 'KEN', 5] ]
Oh, I thought it's from the array section.
let ar = [ 'Albania', 'Bolivia', 'Canada', 'Denmark', 'Ethiopia', 'Finland', 'Germany', 'Hungary', 'Ireland', 'Japan', 'Kenya' ];
let ar2 =[ ]; for( let i=0; i<=ar. length-1 ;i++){ ar2.push( [ar[i],ar[i]. substring(0,3),ar[i].length] ); } console.log(ar2);
@ChintalapudiSaiNitishKumar Aha awesome~
https://github.com/Asabeneh/30-Days-Of-JavaScript/issues/331#issuecomment-1140441730
There is a problem with this solution as the array contains all the capital letters.
const countries = [
"ALBANIA",
"BOLIVIA",
"CANADA",
"DENMARK",
"ETHIOPIA",
"FINLAND",
"GERMANY",
"HUNGARY",
"IRELAND",
"JAPAN",
"KENYA",
];
const array = [];
for (let i = 0; i < countries.length; i++) {
let country = countries[i]; // Storing the current value into @country
array.push(
[
country.substring(0, 1) + country.slice(1).toLowerCase(), // Lowercasing every character instead of first character
country.substring(0, 3), // Only getting characters from 0 - 3 index
country.length // Getting the length of the character in a string
]
);
}
console.log(array); // Logs out the new array