js Task
js Task
1. Grade Evaluator
Write a function getGradeRemark that takes a grade (A, B, C, D, E, F) as input and returns a
remark based on the following criteria:
● "A" → "Excellent"
● "B" → "Very Good"
● "C" → "Good"
● "D" → "Needs Improvement"
● "E" → "Poor"
● "F" → "Fail"
● Any other input → "Invalid Grade"
2. takes a day of the week as input (e.g., "Monday", "Saturday") and returns whether
it's a Weekday or a Weekend.
Conditions:
3. that takes two numbers and an operator (+, -, *, /) as input and returns the result of
the operation.
Conditions:
Conditions:
5. takes a traffic light color as input ("red", "yellow", "green") and returns the
corresponding action:
● "red" → "Stop"
● "yellow" → "Caution"
● "green" → "Go"
● Any other input → "Invalid color"
Conditions:
● If the age is less than 0, return "Invalid age".
● If the age is 0 to 12, return "Child".
● If the age is 13 to 19, return "Teenager".
● If the age is 20 to 35, return "Young Adult".
● If the age is 36 to 60, return "Adult".
● If the age is above 60, return "Senior Citizen"
9. takes a numeric score (0-100) as input and returns the corresponding grade based on
the following conditions:
Conditions:
● If the score is less than 0 or greater than 100, return "Invalid Score".
● 90 - 100 → "A"
● 80 - 89 → "B"
● 70 - 79 → "C"
● 60 - 69 → "D"
● 0 - 59 → "F"
3. Input: arr = [5, 10, 15, 20], remove the last element.
Expected Output: [5, 10, 15]
7. Input: arr = ['a', 'b', 'c', 'd'], remove the first element.
Expected Output: ['b', 'c', 'd']
10. Input: arr = [100, 200, 300, 400, 500], remove the last two elements.
Expected Output: [100, 200, 300]
11. Input: arr = [10, 20, 30], add 5 and 0 at the beginning.
Expected Output: [5, 0, 10, 20, 30]
12. Input: arr = [100, 200, 300], remove the first two elements.
Expected Output: [300]
17. Input: arr = ['a', 'b', 'c', 'd', 'e'], extract ['b', 'c', 'd'].
Expected Output: ['b', 'c', 'd']
19. Input: arr = [10, 20, 30, 40], remove 20 and 30.
Expected Output: [10, 40]
20. Input: arr = ['a', 'b', 'c', 'd'], remove 'c' and insert 'x', 'y'.
Expected Output: ['a', 'b', 'x', 'y', 'd']
22. Input: arr = [1, [2, 3], [4, 5]], flatten one level.
Expected Output: [1, 2, 3, 4, 5]
23. Input: arr = [1, [2, [3, 4], 5]], flatten one level.
Expected Output: [1, 2, [3, 4], 5]
27. Input: arr1 = [10, 20], arr2 = [30, 40], arr3 = [50, 60], merge all.
Expected Output: [10, 20, 30, 40, 50, 60]
28. Input: "helloworld" (Extract hello and world manually)
Expected Output: ["hello", "world"]
29. Input: "applebanana" (Separate apple and banana)
Expected Output: ["apple", "banana"]
30. Input: "abcd1234efgh" (Separate letters and numbers)
Expected Output: ["abcd", "1234", "efgh"]
31. Input: ["hello", "world"]
Expected Output: "helloworld"
32. Input: ["apple", "banana", "grape"]
Expected Output: "applebananagrape"
33. Input: ["abc", "123", "xyz"]
Expected Output: "abc123xyz"
34. Input: arr = [10, 20, 30, 40, 50, 60]
Extract [30, 40] from the array.
Expected Output: [30, 40]
35. Input: arr = ['apple', 'banana', 'grape', 'mango', 'cherry']
Extract the first three elements.
Expected Output: ['apple', 'banana', 'grape']
36. Input: arr = ['red', 'blue', 'green', 'yellow', 'pink']
Extract the last two elements.
Expected Output: ['yellow', 'pink']
37. Input: arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Extract every alternate element starting from index 1 ([2, 4, 6, 8, 10]).
Expected Output: [2, 4, 6, 8, 10]
38. Input: arr = ['a', 'b', 'c', 'd', 'e', 'f']
Extract everything except the first and last elements.
Expected Output: ['b', 'c', 'd', 'e']
39. Input: arr = [100, 200, 300, 400, 500]
Remove 300 and 400.
Expected Output: [100, 200, 500]
40. Input: arr = ['cat', 'dog', 'rabbit', 'elephant']
Replace 'rabbit' with 'lion'.
Expected Output: ['cat', 'dog', 'lion', 'elephant']
41. Input: arr = ['one', 'two', 'three', 'four']
Insert 'zero' at the beginning without removing any element.
Expected Output: ['zero', 'one', 'two', 'three', 'four']
42. Input: arr = [10, 20, 30, 40, 50]
Remove 20 and insert 15, 18 in its place.
Expected Output: [10, 15, 18, 30, 40, 50]
43. Input: arr = ['x', 'y', 'z']
Insert 'a', 'b', 'c' at index 1.
Expected Output: ['x', 'a', 'b', 'c', 'y', 'z']
44. Input: arr = [10, 20, 30, 40, 50, 60, 70]
46. Input: arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
Extract every 2nd element from the array.
Expected Output: ['b', 'd', 'f', 'h']
47. Input: arr = [10, 20, 30, 40, 50, 60]
Extract only the second half of the array.
Expected Output: [40, 50, 60]
48. Input: arr = [100, 200, 300, 400, 500, 600, 700, 800, 900]
Extract the last 3 elements, no matter how long the array is.
Expected Output: [700, 800, 900]
49. Input: arr = [1, 2, 3, 4, 5, 6]
Modify the array so that the first two elements move to the end.
51. Input: arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
Modify the array by removing elements at even indexes.
52. Input: arr = [10, 20, 30, 40, 50, 60, 70, 80, 90]
Modify the array so that the first half swaps with the second
half.
8. Input: ["A", "B", "C"] (Append "!" to each value and print)
Expected Output:
A!
B!
C!
9. Input: [5, 10, 15] (Add 5 to each element and print result)
Expected Output:
10
15
20
Expected Output: 6
Expected Output: 1
18. Input: [10, 20, 30, 40, 50] (Find index of first number
greater than 25)
Expected Output: 2
Expected Output: 2
Expected Output: -1
27. Input: arr1 = [10, 20], arr2 = [30, 40], arr3 = [50,
60]
Merge all three arrays.
Expected Output: [10, 20, 30, 40, 50, 60]
28. Replace numbers with their squares if they are even,
else triple them
Input: [2, 3, 4, 5, 6]
Expected Output: [4, 9, 16, 15, 36]
Input: [1, 2, 2, 3, 4, 4, 5]
Expected Output: [1, 2, 3, 4, 5]
34. Keep only words with vowels at the start and end
37. Keep only the elements that appear more than once
Input: [1, 2, 2, 3, 3, 3, 4, 5]
Expected Output: [2, 2, 3, 3, 3]
Input: [2, 4, 6, 8]
Expected Output: true
num = "42";
];
Input: [1, 2, 2, 3, 3, 3, 4]
Expected Output: { 1: 1, 2: 2, 3: 3, 4: 1 }