Question

Please use proper ES6 JAVASCRIPT SYNTAX including using Let & const correctly Create a function called...

Please use proper ES6 JAVASCRIPT SYNTAX including using Let & const correctly

Create a function called switchLetters that takes a string and an array.

*the switchLetters function should accept two arguments , a string and an array.

*The function switches letters in the string with a "/" if they are included in the array

for example

const arr = ['x', 'a', 'h', 'l', 'd' ]
replaceLetters('hello', arr)
//output: /e//o 

please do this in javascript es6 syntax

0 0
Add a comment Improve this question Transcribed image text
Answer #1
function replaceLetters(str, arr){
   var result = "";
   for(i = 0;i<str.length;i++){
      if(arr.includes(str[i])){
         result += '/';
        }
      else{
         result += str[i];
        }
    }
   return result;
}

const arr = ['x', 'a', 'h', 'l', 'd' ]
replaceLetters('hello', arr)

Add a comment
Know the answer?
Add Answer to:
Please use proper ES6 JAVASCRIPT SYNTAX including using Let & const correctly Create a function called...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • l Question 2 -JS and Python a) Write JavaScript code to create a function called "sortstingsDesc"...

    l Question 2 -JS and Python a) Write JavaScript code to create a function called "sortstingsDesc" that will sort an array of string suppiied as a parameter in descending order. (4) Write Python code to create a function called "addToFront" that will accept two parameters the list of information and the value to be added and place the value to the beginning of the list. [4) b)

  • Programming in C (using only #include <stdio.h>) 1. Create and use a new function called average....

    Programming in C (using only #include <stdio.h>) 1. Create and use a new function called average. 2. Average will accept two integer arguments, (here I will name them sum and n). n is the count of values included in sum. 3. The function will return the integer average of sum. 4. Define and use a function that checks an integer to see if it is positive (returns true if the integer is positive) Note: Choosing proper definition attributes (names, arguments,...

  • IN C++ Create a method called xChar that will replace a specified char in a String...

    IN C++ Create a method called xChar that will replace a specified char in a String with the 'X' character. Your function must use a pointer to search and replace the char. You are not allowed to use array notation to solve this problem. Your function should take as arguments in the CString to search through and a char variable that holds the char to be searched for and replaced. The function should also return the number of replacements made....

  • c++ language 1) Create a function that prints a greeting when called with a name such...

    c++ language 1) Create a function that prints a greeting when called with a name such as greeting ("Elona") 2) Create a function that squares a double number and returns the result as a double. 3) Create a function that takes 5 int numbers and returns the average as a float 4) Create a single function that gives a greeting, calculates the average of 5 grades but does not return a value. Hint: Use return type void and a string...

  • Assignment 1) Your function will only write the Nth character of the array, supplied as a...

    Assignment 1) Your function will only write the Nth character of the array, supplied as a parameter by the caller. This is an example prototype (although you may want to change the return value type, based on the second twist, below). void writeArrayNthBackward(const char [], int, int, int); The first three arguments serve the same purpose as in the iterative example. The fourth argument (an int) supplies the N for the Nth character to print in the array. If n...

  • Searching an array: --Using the template provided, create a method called search that takes an int...

    Searching an array: --Using the template provided, create a method called search that takes an int and an array as parameters. The method search should traverse the array to look for the int. search should print whether it found the int or not, for example: found: 10 did not find: 11 examples (bold face is text entered by user) % java SearchArray 20 found: 20 % java SearchArray 13 did not find: 13 % java SearchArray 100 found: 100 %...

  • Please follow the instructions below to create a code. The instructions are broken down into a...

    Please follow the instructions below to create a code. The instructions are broken down into a few steps. Create the following functions along with a driver for each one confirming it works. The driver needs to test the function with at least 5 different inputs, although more is always better. Be sure to use the function display_startup_banner( ) in all of your drivers. Please create separate files for each code. That is, if you're creating a function called learning_online_is_a_trip( )...

  • write a Matlab program ( solve the three questions). please use array and create your own...

    write a Matlab program ( solve the three questions). please use array and create your own function to check primality Question 1 : [10 points) Write a MATLAB program that will store all the first 1000 prime numbers in an array variable named arr_of_primes. Please note that a prime number is a positive integer that is bigger than or equal to 2 which is divisible only by 1 and itself. Examples of the first 8 primes are: 2, 3, 5,...

  • JavaScript - Sorting Assignment (arrays, classes, functions and higher order functions) Note: Please make sure to...

    JavaScript - Sorting Assignment (arrays, classes, functions and higher order functions) Note: Please make sure to use the ES6 keyword style => instead of the older function. For variables please use keyword let, not var, class and within the constructor, not function. Instructions: - Create a new JavaScript file and name it “Objects.js” - Create a class and make sure to use “names” as the identifier. - Create a constructor with the following elements: first ( value passed will be...

  • Question 9 Problem Solving, Design, Implementation and Testing in MATLAB (a) Create a function called makeLayered t...

    Question 9 Problem Solving, Design, Implementation and Testing in MATLAB (a) Create a function called makeLayered that takes a single parameter n and returns a square 2D array that has 1 at its centre and layers of numbers around this increasing up to and including the value n. For example: makeLayered(3) will return the 2D array 3 3 3 3 3 2 2 3 2 3 2 2 1 3 3 2 2 2 3 3 33 3 3 3...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT