satyacode
Background
JavaScript
1/**
2 * ☕ Chai Tapri Order System - String Basics
3 *
4 * Guddu ki chai tapri hai college ke bahar. Customers order dete hain,
5 * aur Guddu ko string methods use karke orders handle karne hain.
6 * Tu Guddu ka helper hai — basic string methods seekh aur orders process kar!
7 *
8 * Methods to explore: .length, .toUpperCase(), .toLowerCase(),
9 *   .trim(), .includes(), .charAt(), .at()
10 *
11 * Functions:
12 *
13 *   1. getChaiOrderLength(order)
14 *      - Pehle .trim() se extra spaces hatao, phir .length se count karo
15 *      - Agar order string nahi hai, return -1
16 *      - Example: getChaiOrderLength("  masala chai  ") => 11
17 *
18 *   2. shoutChaiOrder(order)
19 *      - Guddu apne helper ko UPPERCASE mein order shout karta hai
20 *      - Pehle .trim() karo, phir .toUpperCase()
21 *      - Agar order string nahi hai ya trim ke baad empty hai, return ""
22 *      - Example: shoutChaiOrder("masala chai") => "MASALA CHAI"
23 *
24 *   3. whisperChaiOrder(order)
25 *      - Jab koi secretly order karta hai, lowercase mein likho
26 *      - Pehle .trim() karo, phir .toLowerCase()
27 *      - Agar order string nahi hai ya trim ke baad empty hai, return ""
28 *      - Example: whisperChaiOrder("ADRAK CHAI") => "adrak chai"
29 *
30 *   4. hasSpecialIngredient(order, ingredient)
31 *      - Check karo ki order mein koi special ingredient hai ya nahi
32 *      - Dono ko .toLowerCase() karo, phir .includes() use karo
33 *      - Agar koi bhi string nahi hai, return false
34 *      - Example: hasSpecialIngredient("Elaichi Masala Chai", "elaichi") => true
35 *
36 *   5. getFirstAndLastChar(order)
37 *      - .charAt(0) se pehla character aur .at(-1) se aakhri character nikalo
38 *      - Pehle .trim() karo
39 *      - Return: { first, last }
40 *      - Agar order string nahi hai ya trim ke baad empty hai, return null
41 *      - Example: getFirstAndLastChar("masala chai") => { first: "m", last: "i" }
42 *
43 * @example
44 *   getChaiOrderLength("  masala chai  ")  // => 11
45 *   shoutChaiOrder("masala chai")          // => "MASALA CHAI"
46 *   hasSpecialIngredient("Elaichi Chai", "elaichi")  // => true
47 */
48export function getChaiOrderLength(order) {
49
50  if(typeof order != "string" ){
51    return -1
52  }
53  return order.trim().length
54}
55
56export function shoutChaiOrder(order) {
57  
58  if(typeof order != "string" || order.length <= 0){
59    return ""
60  }
61  let UpperCaseOrder = order.trim().toUpperCase()
62  return UpperCaseOrder
63}
64
65export function whisperChaiOrder(order) {
66  if(typeof order !== "string" || order.trim().length <= 0){
67    return ""
68  }
69
70  return order.trim().toLocaleLowerCase()
71}
72
73export function hasSpecialIngredient(order, ingredient) {
74
75  if(typeof order != "string" || typeof ingredient != "string"){
76    return false
77  }
78
79  return order.toLowerCase().includes(ingredient.toLowerCase())
80}
81
82export function getFirstAndLastChar(order) {
83  if(typeof order !== "string" || order.trim().length <= 0){
84    return null
85  }
86
87  return {first: order.trim().charAt(0), last:order.trim().at(-1)}
88}
89