Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Enter "hello" ( hello )

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Enter "hello" ( hello )

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Enter "hello" ( hello )

Have an account? Sign In Now

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the question so it can be answered easily.

Please choose the appropriate section so the question can be searched easily.

Please choose suitable Keywords Ex: question, poll.

Browse
Type the description thoroughly and in details.

Choose from here the video type.

Put Video ID here: https://www.youtube.com/watch?v=sdUUx5FdySs Ex: "sdUUx5FdySs".

Enter "hello" ( hello )

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

IT Community and Answers

IT Community and Answers Logo IT Community and Answers Logo

IT Community and Answers Navigation

Search
Ask A Question

Mobile menu

Close
Ask a Question
You can use WP menu builder to build menus
Home/ Questions/Q 1200
Next
john_t
john_tEnlightened
Asked: August 8, 20212021-08-08T14:37:19+00:00 2021-08-08T14:37:19+00:00In: Codewars solutions and discussions

Crash Override codewars js

Every budding hacker needs an alias! The Phantom Phreak, Acid Burn, Zero Cool and Crash Override are some notable examples from the film Hackers.

Your task is to create a function that, given a proper first and last name, will return the correct alias.

  • Two objects that return a one word name in response to the first letter of the first name and one for the first letter of the surname are already given.

  • If the first character of either of the names given to the function is not a letter from A - Z, you should return "Your name must start with a letter from A - Z."

  • Sometimes people might forget to capitalize the first letter of their name so your function should accommodate for these grammatical errors.

var firstName = {A: 'Alpha', B: 'Beta', C: 'Cache' ...}
var surname = {A: 'Analogue', B: 'Bomb', C: 'Catalyst' ...}

aliasGen('Larry', 'Brentwood') === 'Logic Bomb'
aliasGen('123abc', 'Petrovic') === 'Your name must start with a letter from A - Z.'

https://www.codewars.com/kata/578c1e2edaa01a9a02000b7f

 

 

 

const initialCap = (str) => str[0].toUpperCase();
const isValidName = (name) => /^[a-z]/i.test(name);
const aliasGen = (fName, lName) => {
  return (isValidName(fName) && isValidName(lName))
    ? `${ firstName[initialCap(fName)] } ${ surname[initialCap(lName)] }`
    : 'Your name must start with a letter from A - Z.';
}

//

function aliasGen(fname, lname) {
    let output = "";
  
    // transformar tudo em maiuscula
    fname = fname.toUpperCase();
    lname = lname.toUpperCase();
  
    // pegar primeira letra do nome
    let firstLetter = fname[0];
  
    // pegar primeira letra do sobrenome
    let secondLetter = lname[0];
  
    let regexTest = new RegExp('[A-Z]');
  
    // se alguma delas não for letra [A-Z], retornar erro
    if (
      ! regexTest.test(firstLetter)
      ||
      ! regexTest.test(secondLetter)
    ) {
      return "Your name must start with a letter from A - Z.";
    }
    
    // busco nos objetos e monto nova string
    output = `${firstName[firstLetter]} ${surname[secondLetter]}`;
    
  // retorno a string  
  return output;
}

//

function aliasGen(first, last) {
  if('0123456789'.indexOf(first[0]) != -1 || '0123456789'.indexOf(last[0]) != -1) {
    return 'Your name must start with a letter from A - Z.';
  }
  first = first.toUpperCase();
  last = last.toUpperCase();
  return firstName[first[0]] + ' ' + surname[last[0]];
}

//

function aliasGen(first, last){
    if (first[0].match(/[A-Z]/gi) && last[0].match(/[A-Z]/gi)) {
      return firstName[first[0].toUpperCase()] + ' ' + surname[last[0].toUpperCase()]
    } else {
      return 'Your name must start with a letter from A - Z.'
    }
}

Related Questions and Answers:

  • Logical calculator Codewars JS 8 kyu
  • Find the smallest integer in the array JS Codewars 8 kyu
  • Regexp Basics - is it a digit? js codewars
  • Crash Override.js
  • Lario and Muigi Pipe Problem codewars javascript
codewarscodewars katacodewars kata solutioncodewars solutionsjavascriptjs
  • 0
  • 0 0 Answers
  • 121 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse
Enter "hello" ( hello )

Sidebar

Ask A Question

Stats

  • Questions 778
  • Answers 10
  • Best Answers 8
  • Users 2
  • Popular
  • Answers
  • Anonymous

    Logical calculator Codewars JS 8 kyu

    • 2 Answers
  • Anonymous

    Reversed sequence javascript codewars 8 kyu

    • 2 Answers
  • john_t

    Are arrow functions odd?.js

    • 1 Answer
  • john_t
    john_t added an answer function odds(values){ return values.filter(values => values % 2 != 0);… September 12, 2021 at 6:29 pm
  • john_t
    john_t added an answer function toCsvText(array) { return array.join('\n'); } https://www.codewars.com/kata/5a34af40e1ce0eb1f5000036/train/javascript September 12, 2021 at 6:20 pm
  • john_t
    john_t added an answer function solution(a, b){ return a.length < b.length ? a +… September 7, 2021 at 8:04 pm

Related Questions

  • Anonymous

    Short Long Short codewars js

    • 1 Answer
  • john_t

    Fuel Calculator.js

    • 0 Answers
  • john_t

    Freudian translator.js

    • 0 Answers

Top Members

john_t

john_t

  • 774 Questions
  • 55k Points
Enlightened
Jacob

Jacob

  • 1 Question
  • 21 Points
Begginer

Trending Tags

codewars codewars js 8 kyu codewars kata codewars kata solution codewars solutions data studio ga individual qualification exam answers google ads Google Analytics Individual Qualification google analytics individual qualification exam answers javascript js Segment Conversion Type Name

Explore

  • Questions
    • New Questions

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.