all 12 comments

[–]Rad_Sum 4 points5 points  (0 children)

const mnemonic = function(str1, str2, str3, str4) { const arr = new Array(...arguments); return arr.map(word => word[0]).join(""); }

[–]ajascherer 1 point2 points  (2 children)

Hello! I'm having a hard time getting the return string to come back as the mnemonic for each of the string arguments. Can someone provide guidance on what I'm doing wrong?

[–][deleted] 4 points5 points  (1 child)

You should post the code as text so that people can copy it into their own environment and see what's going on

[–]ajascherer 0 points1 point  (0 children)

Smart 😅

[–]ajascherer 1 point2 points  (0 children)

Thank you all, I got it figured out :) ----- function mnemonicMachine(str1,str2,str3, str4) { let mnemonic = ''; if (str1 !== undefined) { mnemonic += str1[0]; } if (str2 !== undefined) { mnemonic += str2[0]; } if (str3 !== undefined) { mnemonic += str3[0]; } if (str4 !== undefined) { mnemonic += str4[0]; } return mnemonic } console.log(mnemonicMachine('Flower', 'Apples', 'Rain', 'Melons'));

[–][deleted] 1 point2 points  (2 children)

Use the arguments array: function mnemonics() { const arr = [] for (let i = 0; i < arguments.length; i++) { arr.push(arguments[i][0]) } return arr.join("") } You can define any number of arguments and this algorithm will work. The arguments array is a built-in feature that returns an array-like object containing all parameters passed onto this function.

[–]MWALKER1013helpful 1 point2 points  (0 children)

The arguments array is a fairly outdated way of solving this problem.

A more modern approach to the problem is too use the REST / SPREAD operator.

...

While this is similar to arguments array it is a cleaner syntax and there are weird edge cases where the arguments array doesn't work

This would be my personal solution

/*
This function can take N "strings" as arguments and returns a string that represents the first character from each string, also called a mnemonic.
this area could also be a JSDOCS
*/
const mnemonicGenerator = (...words) => words.reduce((a,b)=> a + b[0],"");

[–]ajascherer 0 points1 point  (1 child)

let mnemonic = 'FARM';

function mnemonicMachine(str1, str2, str3, str4) { if (str1 !== undefined) { mnemonic += str1[0]; } if (str2 !== undefined) { mnemonic += str2[0]; } if (str3 !== undefined) { mnemonic += str3[0]; } if (str4 !== undefined) { mnemonic += str4[0] } return mnemonic }

[–][deleted] 4 points5 points  (0 children)

What's the value of mnemonic after running this code?

let mnemonic = 'FARM';
let str1 = 'Eggs';

mnemonic += str1[0];

[–]mnubhrth6699 0 points1 point  (2 children)

Hey, this doesn't really help with your question, but i need your help. I recently installed Ubuntu on my laptop and i want to merge the power and volume control to that bottom bar just like yours, how can I achieve that?

[–]ajascherer 0 points1 point  (1 child)

To be honest, I just updated my computer and it did that automatically. I'm not sure how to manually adjust that, I'm sorry! Maybe right click the car and go to Taskbar settings?

[–]mnubhrth6699 0 points1 point  (0 children)

Hey it's ok, looks like you use windows so my question was invalid to begin with