String representation of a failed test

While working on some coding exercises on codewars, I came across a simple one that requires creating a function called shortcut to eliminate all the lowercase vowels in a given string. Here are some examples:

shortcut("codewars") // --> cdwrs
shortcut("goodbye")  // --> gdby

As a newbie, I tried to come up with a solution, but unfortunately, it doesn't seem to work and I'm not sure why.

function shortcut(string){
  var stage1 = string.split('');  

  for (i = string.length-1; i >= 0; i--) {
    if (stage1[i] === "a"|| 
        stage1[i] === "e"|| 
        stage1[i] === "i"||
        stage1[i] === "o"||
        stage1[i] === "u") {
      stage1.splice(i,1)
    ;}
  };

  string = stage1.join('');
  return shortcut;
}

I have a feeling that the issue might be related to how I'm handling arrays and strings. If you have any suggestions or alternative methods to achieve the same result, please let me know.

Answer №1

The issue lies in your return statement - you are currently returning the function instead of a string value.

Answer №2

Employing regular expressions:

let sentence = 'programming';

let regexPattern = /[aeiou]/g;

let finalOutput = sentence.replace(regexPattern, '');

document.write(finalOutput);

Answer №3

For those keen on learning about Regular Expression!

function abridge(inputString) {
    return inputString.replace(/[aeiou]/g, "");
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to implement Google Tag Manager using the next/script component in Next.js 11?

Version 11 of Next.js recently introduced a new approach with the Script component offering various strategies. To avoid duplicate tags, it is advised to implement Google TagManager using the afterInteractive strategy. In my experimentation: // _app.js ...

The b-overlay feature in b-modal hides the modal body from view

Currently, I am facing an issue with Vue Bootstrap. When I include b-overlay with the no-wrap prop in b-modal, the modal body becomes invisible even when the overlay is not active. For reference, you can check out this example: https://codesandbox.io/s/fr ...

Is it possible to use the AngularJS function with the <div> HTML element?

I am facing an issue with displaying a modal when clicking on a <div> element. The function assigned to show the modal by changing the CSS property 'display' from 'none' to 'block' works fine when attached to a button, b ...

Discover the method for populating Select2 dropdown with AJAX-loaded results

I have a basic select2 box that displays a dropdown menu. Now, I am looking for the most effective method to refresh the dropdown menu every time the select menu is opened by using the results of an AJAX call. The ajax call will yield: <option value=1 ...

Update in slide height to make slider responsive

My project involves a list with text and images for each item: <div class="slider"> <ul> <li> <div class="txt"><p>First slogan</p></div> <div class="img"><img src="http://placehold.it/80 ...

Can you provide the regular expression that will reject the character "?"

Can you help me verify that my form does not accept double quotes? Validators.pattern(/^(?!").*/g) The current solution is not functioning properly. I want to allow all characters except for double quotes. ...

Fill input text fields with values based on dropdown selection and start with 2 input fields pre-filled

Initially, the issue is that there are 2 input text fields displayed. Depending on the selection from a drop-down menu ranging from 2 to 6, additional input fields should be added or removed. Here's my code: function addElements(selectElement) { va ...

Using Special Characters in React JS Applications

When handling CSV uploads with accented characters such as émily or ástha, I encountered the need to encode and pass them to the backend. Experimenting with different approaches, I tried adjusting the file type in FormData from 'text/plain' to ...

Understanding the behavior of the enter key in Angular and Material forms

When creating forms in my MEAN application, I include the following code: <form novalidate [formGroup]="thesisForm" enctype="multipart/form-data" (keydown.enter)="$event.preventDefault()" (keydown.shift.enter)="$ev ...

Is it possible to protect passwords internally via URL and AJAX?

During my time at a previous company, we had an internal website that required a password to be entered at the end of the URL in order to view it. I suspect this was done using AJAX, but I am unsure. Even if AJAX was used, I do not know how to code it myse ...

add component automatically upon selection

Imagine I have a special <SelectPicker/> element that allows me to choose an option. What I am trying to figure out is how I can include another <SelectPicker/> once I have made a selection. function DynamicComponent() { const [state, setSta ...

Accessing React Context globally using the useContext hook

I'm feeling a bit puzzled about how the useContext hook is intended to function in a "global" state context. Let's take a look at my App.js: import React from 'react'; import Login from './Components/auth/Login'; import &apos ...

Finding the initial unique character in a string with Unordered_map in C++

I am attempting to use an unordered_map in C++ to identify the first unique character in a string. You can find the problem on LeetCode. Here is my code snippet: int firstUniqChar(string s) { unordered_map<char, int> m; for(int i = 0; i < ...

Send the Children prop to the React Memo component

Currently, I am in the stage of enhancing a set of React SFC components by utilizing React.memo. The majority of these components have children and the project incorporates TypeScript. I had a notion that memo components do not support children when I en ...

Unable to access the uploaded file on the server

Scenario : When a user uploads an image and clicks on the "save" button, I successfully save the image on the server with 777 permission granted to the folder... https://i.sstatic.net/gcIYk.png Problem : However, when I try to open the image, it does n ...

What is the process for adding JSON data to a dropdown menu using PHP AJAX?

I am trying to populate a select html element with data from a list of JSON results. Here is the code I have attempted: JSON output: jquery loop on Json data using $.each {"Eua":"Eua","Ha'apai":"Ha'apai",& ...

AngularJS: Issue with watching arrays and deep $watch functionality

I'm having trouble using the $watch function in AngularJS with an array of boolean values. I want to display a message when there's a change in the array, but it's not working as expected. Check out this code example where the array values ...

Sending AJAX information to multiple pages

I have created an HTML page where I am struggling to pass two variables using the POST method to a PHP page. The PHP page is supposed to accept these variables and then call an API to retrieve data based on them. However, my challenge is in receiving this ...

What is the proper way to structure the ng-options syntax in AngularJS?

I received an array from a REST service and I am attempting to generate a dropdown menu based on that data. Check out the jsfiddle example here $scope.reasons = [{ "languageLanguageId": { "languageId": 1, "lastUpdate": "2015-05-08T11:14:00+03:00" ...

Creating Vue components based on a deeply nested data structure

Is there a way to efficiently utilize a nested object for generating Vue components? My nested object structure is as follows: "api": { "v1": { "groups": { "create": true, "get": true, ...