30-Days-Of-JavaScript icon indicating copy to clipboard operation
30-Days-Of-JavaScript copied to clipboard

Day6: Exercise2: problem 6:

Open hafsamubarak opened this issue 2 years ago • 4 comments

I get confused with this question I know it's so easy but I cannot write the exact syntax for it

hafsamubarak avatar May 03 '22 19:05 hafsamubarak

@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] ]

hafsamubarak avatar May 08 '22 20:05 hafsamubarak

Oh, I thought it's from the array section.

devprotim avatar May 09 '22 10:05 devprotim

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~

Heartbeats-R avatar Jun 28 '22 03:06 Heartbeats-R

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

gurvirbaraich avatar Feb 19 '23 15:02 gurvirbaraich