Functional Programming Answers

Questions: 109

Answers by our Experts: 81

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Check values in the Array is a String

Given an array

myArray, write a JS program to check whether each value of the array is a string or not using the array method every().Input

  • The input will be a single line containing an array myArray

Output

  • The output should be a single line containing a boolean value


Sample Input 1

[ 'frozen', 'rock', 'stained', 'basket' ]


Sample Output 1

true


Sample Input 2

[ 'recycling', 70, 'pastime', 'animal' ]


Sample Output 2

false




Square at Alternate Indices

Given an array

myArray of numbers, write a function to square the alternate numbers of the myArray, starting from index 0 using the array method map.Input

  • The input will be a single line containing an array myArray

Output

  • The output should be a single line containing an array with alternate numbers squared

Constraints

  • Each value in the array must be a number


Sample Input 1

[ 1, 2, 3, 4, 5 ]


Sample Output 1

[ 1, 2, 9, 4, 25 ]


Sample Input 2

[ 2, 4 ]


Sample Output 2

[ 4, 4 ]




Filter Unique Characters

Given a string

myString as an input, write a JS program to find the unique characters from the myString.

Quick Tip

You can use the array method indexOf().

Input

  • The input will be a single line containing a string myString

Output

  • The output should be a single line containing an array of unique characters


Sample Input 1

Was it a cat I saw?


Sample Output 1

[

'W', 'a', 's', ' ',

'i', 't', 'c', 'I',

'w', '?'

]


Sample Input 2

I did, did I?


Sample Output 2

[ 'I', ' ', 'd', 'i', ',', '?' ]




String Starts or Ends with given String

Given an array

stringsArray of strings, and startString, endString as inputs, write a JS program to filter the strings in stringsArray starting with startString or ending with endString.

Quick Tip

You can use the array method filter() and logical operator OR ( || ).

Input

  • The first line of input contains a string stringsArray
  • The second line of input contains a string startString
  • The third line of input contains a number endString

Output

  • The output should be a single line containing an array of filtered strings


Sample Input 1

['teacher', 'friend', 'cricket', 'farmer', 'rose', 'talent', 'trainer']

t

r


Sample Output 1

[ 'teacher', 'farmer', 'talent', 'trainer' ]


Sample Input 2

['dream', 'player', 'read', 'write', 'trend']

p

d


Sample Output 2

[ 'player', 'read', 'trend' ]




String Slicing

Given two strings

inputString and subString as inputs, write a JS program to slice the inputString if it includes the subString. Slice the inputString starting from the subString to the end of the inputString.Input

  • The first line of input contains a string inputString
  • The second line of input contains a string subString

Output

  • The output should be a sliced string or inputString (if the inputString does not include the subString)

Sample Input 1

JavaScript

S


Sample Output 1

Script


Sample Input 2

Language

air


Sample Output 2

Language




Split and Replace

Given three strings

inputString, separator and replaceString as inputs. Write a JS program to split the

inputString with the given separator and replace strings in the resultant array with the replaceString whose length is greater than 7.

Quick Tip

  • You can use the string method split()
  • You can use the array method map()

Input

  • The first line of input contains a string inputString
  • The second line of input contains a string separator
  • The third line of input contains a string replaceString

Output

  • The output should be a single line containing the strings separated by a space


Sample Input 1

JavaScript-is-amazing

-

Programming


Sample Output 1

Programming is amazing


Sample Input 2

The&Lion&King

&

Tiger


Sample Output 2

The Lion King




Check values in the Array is a String

Given an array

myArray, write a JS program to check whether each value of the array is a string or not using the array method every().Input

  • The input will be a single line containing an array myArray

Output

  • The output should be a single line containing a boolean value


Sample Input 1

[ 'frozen', 'rock', 'stained', 'basket' ]


Sample Output 1

true


Sample Input 2

[ 'recycling', 70, 'pastime', 'animal' ]


Sample Output 2

false




A new bakeshop is giving 50% off on all its products for its first 20

customers (regardless of age) for the store opening. After the 20th

customer, there will 10% discounts and all senior citizens receive an

additional 20% discount.

Write a pseudocode and create PHP program that performs the

necessary calculations, using Switch statement. Your program should

prompt the user for the total amount, calculate and display appropriate

discounts. Make the program as realistic as possible.


What is Lattice-based access control? Briefly describe with suitable figures.
I'm sorry if i put the wrong thing for this question but here is my question

You have been asked to write a program that will prompt the user for his or her t-shirt order and display it. The order will include the size, color, and design of the shirt. Read the pseudocode for the program:

Input:
Ask user what size shirt—small, medium, large, or extra-large
Ask user what color—blue, green, red, or yellow
Ask user what design—chevron, solid, or stripes
Output:
Print a message that clearly displays the user's shirt size, color, and design. (8 points)
LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS