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 ( || ).
function main() {
const stringsArray = JSON.parse(readLine().replace(/'/g, '"'));
const startString = readLine();
const endString = readLine();
/* Write your code here */
}
Gardening
We have a task to do Gardening.
Given two boolean values
isGrassTrimmerFound and isWaterHosePipeFound as inputs, create three JS promises using async/await and try/catch blocks.
/* Please do not modify anything above this line */
function main() {
const isGrassTrimmerFound = JSON.parse(readLine());
const isWaterHosePipeFound = JSON.parse(readLine());
/* Write your code here */
const myPromise = async () => {
try {
/* Write your code here */
} catch(error) {
/* Write your code here */
}
};
myPromise();
}
String Slicing
Given two strings
Sample Input 1
JavaScript
S
Sample Output 1
Script
Sample Input 2
Language
air
Sample Output 2
Language
Trekking Kit
function Trekking(kit, item) {
this.kit = kit;
this.item = item;
}
function main() {
const item = readLine();
const trekkingKit = {
ruckSackBag : true,
clothes: ["Shirt", "T-Shirt/Full sleeves","Jeans"],
firstAid: true,
waterBottle: "2 liters",
sunGlasses: "UV Protection",
headTorch: true,
medicines: true,
footWear: "Non-skid",
food: ["dry fruits", "nuts", "chocolate bars"]
};
/* Write your code here */
}
Sample Input 1
ruckSackBag
Sample Output 1
true
Sample Input 2
surfboard
Sample Output 2
false
i want code in between write code here
Unite Family
Given three objects
SampleInput 1
{'surname' : 'Williams', 'city': 'Columbia'}
{'dish': 'cakes'}
{'pet': 'Rocky'}
Sample Output 1
Mr and Mrs Williams went to a picnic in Columbia with a boy and a pet Rocky. Mrs Williams made a special dish "cakes"
Sample Input 2
{'surname' : 'Jones', 'city': 'Los Angeles'}
{'dish': 'puddings'}
{'pet': 'Peter'}
Sample Output 2
Mr and Mrs Jones went to a picnic in Los Angeles with a boy and a pet Peter. Mrs Jones made a special dish "puddings"
Array of Strings to UpperCase
Given an array
Sample Input 1
[ 'book', 'table', 'strawberries', 'lemons' ]
Sample Output 1
[ 'BOOK', 'TABLE', 'STRAWBERRIES', 'LEMONS' ]
Sample Input 2
[ 'my best friend', 'florida', 'winter' ]
Sample Output 2
[ 'MY BEST FRIEND', 'FLORIDA', 'WINTER' ]
Trekking Kit
Given an object
trekkingKit in the prefilled code and item item as an input, write a JS program to add the method isKitContains to the constructor function Trekking using the prototype.
The method
isKitContains checks whether the trekkingKit contains the given item.
Quick Tip
The Object.getOwnPropertyNames() method gives an array containing the properties of the object.
Input
The input will be a single line containing a string
item
Output
The output should be a single line containing a boolean value
Sample Input 1
ruckSackBag
Sample Output 1
true
Sample Input 2
surfboard
Sample Output 2
false
Hotel Bill
A Hotel is offering discounts to its customers.
Given charge per day
dayCharge based on category and numbers of days customer stayed days as inputs, write a JS arrow function to return the total bill with the discount.
Quick Tip
Apply discounts on the following basis,
Sample Input 1
200
3
Sample Output 1
570
Sample Input 2
180
1
Sample Output 2
180
Sample Input 2
400
6
Sample Output 2
2040
Search Item in a Mart
Given an array mart of objects in the prefilled code and categoryOfItem, item as inputs, create a JS promise, resolve with "Item Found" text, if the categoryOfItem matches with the category and the corresponding items list includes the item reject with "Category Not Found" text, if the categoryOfItem does not match with any catergory in the mart reject with "Item Not Found" text, if the items list does not include item Use async/await and try/catch blocks.
Quick Tip
You can use array methods find() and includes().
Input
The first line of input contains a string categoryOfItem The second line of input contains a number item
Output
The output should be a single line string with the appropriate message
Sample Input 1
pulses
green gram
Sample Output 1
Item Found
Sample Input 2
detergents
tide
Sample Output 2
Category Not Found
Unite Family
Given three objects
Sample Input
{'surname' : 'Jones', 'city': 'Los Angeles'}
{'dish': 'puddings'}
{'pet': 'Peter'}
Sample Output
Mr and Mrs Jones went to a picnic in Los Angeles with a boy and a pet Peter. Mrs Jones made a special dish "puddings"