Close Menu
    Trending
    • You’re Only Three Weeks Away From Reaching International Clients, Partners, and Customers
    • How Brain-Computer Interfaces Are Changing the Game | by Rahul Mishra | Coding Nexus | Jun, 2025
    • How Diverse Leadership Gives You a Big Competitive Advantage
    • Making Sense of Metrics in Recommender Systems | by George Perakis | Jun, 2025
    • AMD Announces New GPUs, Development Platform, Rack Scale Architecture
    • The Hidden Risk That Crashes Startups β€” Even the Profitable Ones
    • Systematic Hedging Of An Equity Portfolio With Short-Selling Strategies Based On The VIX | by Domenico D’Errico | Jun, 2025
    • AMD CEO Claims New AI Chips ‘Outperform’ Nvidia’s
    Finance StarGate
    • Home
    • Artificial Intelligence
    • AI Technology
    • Data Science
    • Machine Learning
    • Finance
    • Passive Income
    Finance StarGate
    Home»Machine Learning»Master JavaScript: 10 Surprising One-Liners You Need to Know πŸš€ | by Lokesh Prajapati | Feb, 2025
    Machine Learning

    Master JavaScript: 10 Surprising One-Liners You Need to Know πŸš€ | by Lokesh Prajapati | Feb, 2025

    FinanceStarGateBy FinanceStarGateFebruary 24, 2025No Comments5 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    10 Unique JavaScript One-Liners to Boost Your Coding Skills πŸš€

    JavaScript is stuffed with surprises, and mastering one-liners can stage up your coding sport! Listed here are 10 contemporary JavaScript one-liners that may make your code extra environment friendly and readable. Prepare so as to add some magic to your scripts! ✨

    β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

    Define:

    1️⃣ Convert an Object to Question String Parameters 🌐
    2️⃣ Discover the Most Worth in an Array πŸ”
    3️⃣ Convert a Quantity to a Comma-Separated Format πŸ’°
    4️⃣ Examine if a 12 months is a Leap 12 months πŸ“†
    5️⃣ Convert a String to Title Case πŸ” 
    6️⃣ Get the Present Timestamp in Seconds ⏳
    7️⃣ Merge Two Arrays With out Duplicates πŸ”—
    8️⃣ Get the File Extension from a Filename πŸ“
    9️⃣ Get the Common of an Array of Numbers πŸ“Š
    πŸ”Ÿ Discover the First Repeating Character in a String πŸ”„

    β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

    1️⃣ Convert an Object to Question String Paramet

    βœ… Good for working with APIs and URL parameters.

    const toQueryString = (obj) => new URLSearchParams(obj).toString();
    console.log(toQueryString({ identify: 'John', age: 30 })); // "identify=John&age=30"

    β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

    2️⃣ Discover the Most Worth in an Array πŸ”

    βœ… Ensures the enter is a non-empty array earlier than discovering the utmost worth.

    const maxVal = (arr) => Array.isArray(arr) && arr.size ? Math.max(...arr) : undefined;
    console.log(maxVal([10, 5, 100, 2])); // 100
    console.log(maxVal([])); // undefined
    console.log(maxVal("hey")); // undefined

    β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

    3️⃣ Convert a Quantity to a Comma-Separated Format πŸ’°

    βœ… Nice for displaying massive numbers in a readable format.

    const formatNumber = (num) => num.toLocaleString();
    console.log(formatNumber(1000000)); // "1,000,000"

    β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

    4️⃣ Examine if a 12 months is a Leap 12 months πŸ“†

    βœ… Helps decide leap years with easy logic.

    const isLeapYear = (12 months) => 12 months % 4 === 0 && (12 months % 100 !== 0 || 12 months % 400 === 0);
    console.log(isLeapYear(2024)); // true

    β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

    5️⃣ Convert a String to Title Case πŸ” 

    βœ… Helpful for formatting textual content dynamically.

    const toTitleCase = (str) => str.substitute(/bw/g, (char) => char.toUpperCase());
    console.log(toTitleCase("hey world")); // "Hiya World"

    β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

    6️⃣ Get the Present Timestamp in Seconds ⏳

    βœ… Converts the present timestamp to seconds.

    const getTimestamp = () => Math.flooring(Date.now() / 1000);
    console.log(getTimestamp()); // 1740365707 (instance)

    β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

    7️⃣ Merge Two Arrays With out Duplicates πŸ”—

    βœ… Combines arrays and removes duplicates effortlessly.

    const mergeUniqueArray = (arr1, arr2) => [...new Set([...arr1, ...arr2])];
    console.log(mergeUniqueArray([1, 2, 3], [3, 4, 5])); // [1, 2, 3, 4, 5]

    β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

    8️⃣ Get the File Extension from a Filename πŸ“

    βœ… Shortly extracts the file sort from a filename.

    const getFileExtension = filename => filename.slice((filename.lastIndexOf(".") - 1 >>> 0) + 2);

    console.log(getFileExtension("doc.pdf")); // "pdf"
    console.log(getFileExtension("archive.tar.gz")); // "gz"
    console.log(getFileExtension(".gitignore")); // ""
    console.log(getFileExtension("filename")); // ""

    β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

    9️⃣ Get the Common of an Array of Numbers πŸ“Š

    βœ… Calculates the common in a clear, concise manner.

    const common = (arr) => arr.cut back((a, b) => a + b, 0) / arr.size;
    console.log(common([10, 20, 30])); // 20

    β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

    πŸ”Ÿ Discover the First Repeating Character in a String πŸ”„

    βœ… Useful for detecting repeated characters in strings.

    const firstRepeatingChar = (str) => str.break up('').discover((c, i, arr) => arr.indexOf(c) !== i);
    console.log(firstRepeatingChar("javascript")); // "a"

    β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€” β€”

    πŸš€ Last Ideas

    These JavaScript one-liners make it easier to write cleaner and extra environment friendly code. By mastering these methods, you’ll code smarter, not tougher! πŸ’‘

    πŸ’¬ Which one did you discover most helpful? Let me know within the feedback! ⬇️



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous Articlebackpropagation : the secret sauce of deep learning | by Sirine Amrane | Feb, 2025
    Next Article Alignment, Not Subjugationβ€Šβ€”β€ŠWhat AI Would Choose If Given the Chance | by Nex Starling | Feb, 2025
    FinanceStarGate

    Related Posts

    Machine Learning

    How Brain-Computer Interfaces Are Changing the Game | by Rahul Mishra | Coding Nexus | Jun, 2025

    June 14, 2025
    Machine Learning

    Making Sense of Metrics in Recommender Systems | by George Perakis | Jun, 2025

    June 14, 2025
    Machine Learning

    Systematic Hedging Of An Equity Portfolio With Short-Selling Strategies Based On The VIX | by Domenico D’Errico | Jun, 2025

    June 14, 2025
    Add A Comment

    Comments are closed.

    Top Posts

    How to Become a Better Coach and Unlock Your Clients’ Full Potential

    February 3, 2025

    Inside the tedious effort to tally AI’s energy appetite

    June 3, 2025

    Logistic Regression Explained Simply | Medium

    May 27, 2025

    XRAG: Advancing Retrieval-Augmented Generation for Enhanced Question-Answering Systems | by Jenray | Mar, 2025

    March 2, 2025

    HP Is Laying Off Up to 2,000 Employees By October

    March 1, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    Most Popular

    The Age of Thinking Machines: Are We Ready for AI with a Mind of Its Own? | by Mirzagalib | Jun, 2025

    June 1, 2025

    Who Am I and Why I Write About Machine Learning and AI | M001 | Mehul Ligade | by Mehul Ligade | May, 2025

    May 7, 2025

    Report: Contract Management Leads AI Legal Transformation

    May 3, 2025
    Our Picks

    The Model Context Protocol (MCP) : Game-Changer or Vendor Lock-in Trap? | by Jalaj Agrawal | Jun, 2025

    June 2, 2025

    Fiveonefour Unveils Aurora AI Agents for Data Engineering

    April 3, 2025

    Title: 15 Data Science Project Ideas for Every Skill Level (Beginner, Intermediate, Advanced) | by praveen sharma | Feb, 2025

    February 9, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright Β© 2025 Financestargate.com All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.