Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input){
- const changeCase = (command, string)=>{
- if(command === 'upper'){
- return string.toUpperCase();
- }else if(command === 'lower'){
- return string.toLowerCase();
- }
- }
- const getDomain = (string, count)=>{
- console.log(string.substring(string.length - count));
- }
- const getUsername = (string) =>{
- let index = string.indexOf('@');
- if(index === -1){
- console.log("The email " + string + " doesn't contain the @ symbol.");
- }else{
- console.log(string.substring(0,index));
- }
- }
- const replaceWith = (string,char)=>{
- let output = string;
- while(output.indexOf(char) > -1){
- output = output.replace(char,'-');
- }
- return output;
- }
- const encrypt = (string) => {
- let arr = string.split('');
- let output = arr.map(letter=>{
- return letter.charCodeAt()
- }).join(' ');
- console.log(output);
- }
- let email = input.shift();
- for (const line of input) {
- if(line === 'Complete'){
- break;
- }
- let [firstArg, secondArg] = line.split(' ');
- switch(firstArg){
- case 'Make':
- email = changeCase(secondArg.toLowerCase(), email);
- console.log(email);
- break;
- case 'GetDomain':
- getDomain(email,Number(secondArg));
- break;
- case 'GetUsername':
- getUsername(email);
- break;
- case 'Replace':
- email = replaceWith(email, secondArg);
- console.log(email);
- break;
- case 'Encrypt':
- encrypt(email);
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment