🧮 Finding the Median in JavaScript – Quick Tip! While working with numerical data, calculating the median is a common task. Here’s a clean and efficient way to find the median of an array in JavaScript 🧠 How it works: Sort the array in ascending order. Find the middle index. If the length is odd, return the middle element. If the length is even, return the average of the two middle elements. 💡 Output: For [1, 3, 2, 5, 4], the sorted array is [1, 2, 3, 4, 5] → Median = 3 ✅ A simple yet powerful example of handling statistics in JavaScript. #JavaScript #Coding #WebDevelopment #Learning #CodeSnippet #ProgrammingTips
How to Calculate Median in JavaScript
More Relevant Posts
-
Primitive vs Non-Primitive Data Type in JavaScript I remember when I was learning Javascript, I often got confused between primitive and non-primitive (or reference) types. But as soon as I could visualize how it works in memory — everything fell into place! 💡 Here’s the key idea 👇 🧱 Primitive (as in string, number, boolean, null, undefined, symbol etc) → store plain values into the memory (stack). 🧩 Non-Primitive types (object, array, function) → store addresses (references) to values in memory (heap). So when we copy a primitive value, it becomes a new one. Non-primitive types are different: when we copy them, the two variables still point to the same object! 😯 So knowing this small detail really HELPS a LOT in debugging and Understanding JavaScript behavior better. 💬 Have you ever been surprised by how objects or arrays behave in JS? #JavaScript #WebDevelopment #CodingJourney #FrontendDevelopment #LearnToCode #Programming #DeveloperCommunity #CodingBasics
To view or add a comment, sign in
-
-
“Daily Temperatures” Using Stack in JavaScript ♨️ 👉 Day 19 / Day 93 👈 Description: 👉 The goal is to find out how many days you have to wait until a warmer temperature. ✅ Approach: 👉 Traverse the array from right to left. 👉Maintain a stack to store indices of temperatures in decreasing order. 👉 For each day, pop all smaller or equal temperatures. 👉 The difference between the current index and top of stack gives the number of days to wait. This method ensures O(n) time complexity instead of a brute-force O(n²). #JavaScript #CodingChallenge #DSA #InterviewPreparation #FrontendDeveloper #ProblemSolving #100DaysOfCode #TechLearning #LeetCode #Algorithms
To view or add a comment, sign in
-
-
Today I learned three powerful JavaScript methods: map(), filter(), and reduce() 🧠 These methods make working with arrays super efficient — instead of writing long loops, you can do everything in just a few lines of clean code! map() → transforms each element filter() → filters elements based on condition reduce() → reduces all elements into a single value (like sum or total) Learning how they work together really changed the way I think about data manipulation in JS 😍 #JavaScript #FrontendDevelopment #CodingJourney #WebDevelopment #LearningEveryday
To view or add a comment, sign in
-
🚀 Master JavaScript Arrays — From Basics to Advanced! Arrays are the backbone of data manipulation in JavaScript — from handling lists of items to building complex data structures. 📊 This guide covers everything you need to know — ✅ Creating, accessing, and modifying arrays ✅ Copying & cloning techniques (mutable vs. immutable) ✅ Modern methods like toReversed(), toSorted(), toSpliced(), and with() ✅ Deep dive into static & iterator methods (map, filter, reduce, find, flatMap, and more) ✅ Practical exercises and real-world challenges Whether you’re a beginner brushing up your fundamentals or an intermediate dev polishing your skills, this post is packed with examples and clear explanations to make Arrays second nature. 💪 📄 Download the full PDF below and start mastering one of the most powerful parts of JavaScript today. #JavaScript #FrontendDevelopment #WebDevelopment #Coding #Learning #Arrays #JSDeveloper
To view or add a comment, sign in
-
🚀 Master JavaScript Arrays — From Basics to Advanced! Arrays are the backbone of data manipulation in JavaScript — from handling lists of items to building complex data structures. 📊 This guide covers everything you need to know — ✅ Creating, accessing, and modifying arrays ✅ Copying & cloning techniques (mutable vs. immutable) ✅ Modern methods like toReversed(), toSorted(), toSpliced(), and with() ✅ Deep dive into static & iterator methods (map, filter, reduce, find, flatMap, and more) ✅ Practical exercises and real-world challenges Whether you’re a beginner brushing up your fundamentals or an intermediate dev polishing your skills, this post is packed with examples and clear explanations to make Arrays second nature. 💪 📄 Download the full PDF below and start mastering one of the most powerful parts of JavaScript today. #JavaScript #FrontendDevelopment #WebDevelopment #Coding #Learning #Arrays #JSDeveloper
To view or add a comment, sign in
-
🫢 Ever wondered what happens behind the scenes when you reassign a value in JavaScript? 🤔 👉 When you update a primitive data type (like string, number, boolean, undefined, null, symbol, or bigint), you’re not actually changing the existing value. 👉 Instead, JavaScript silently creates a new value in memory and points your variable to it. 🎯 👉 It’s like getting a brand-new notebook instead of erasing the old one — the old still exists, but you’ve just started fresh. 📒 ✨ So, while it looks like you’re modifying the value, you’re actually reassigning a new memory reference every time. 🌠 As they say, “Appearances can be deceiving.” 😉 The value seems to change, but deep down, it never truly does! 💡 In short: We often know that strings are immutable, but here’s the twist — all primitive data types are immutable in JavaScript! 🔥 💬 Idiom: “Appearances can be deceiving.” — Things may not be as they seem; something that looks one way on the surface may actually be very different underneath. #JavaScript #CodingTips #Programming #TechInsights #LearnToCode #DeveloperLife #FrontendDevelopment #CodeWisdom #ProfessionalLearning #CareerGrowth #JS #WebDevelopment
To view or add a comment, sign in
-
-
Learning never stops — and today’s focus was on Template Literals in JavaScript ✨ Template literals are an elegant upgrade over traditional string concatenation. They make code cleaner, more readable, and dynamic — especially when dealing with multi-line strings or injecting variables directly inside strings. Example: const name = "Tom"; const course = "MERN Stack"; console.log(`Hello ${name}, welcome to the ${course} learning journey!`); Template literals also make it easy to: 1.Embed expressions directly in your strings (${expression}) 2.Create multi-line strings without messy \n 3.Combine dynamic data effortlessly This small but powerful ES6 feature makes my code not only neater but also more expressive. 🚀 #JavaScript #TemplateLiterals #ES6 #WebDevelopment #CodingJourney #LearnToCode #MERNStack #CodeEveryday #JavaScriptLearning #FrontendDevelopment #DeveloperLife #WomenInTech #100DaysOfCode #TechSkills #CodingCommunity #CleanCode #StringInterpolation #WebDevLearning #TechGrowth
To view or add a comment, sign in
-
🚀 Day 7 of My 30 Days of JavaScript Journey ✅ Challenge: Array Reduce Transformation (LeetCode #2626) Write a function reduce(nums, fn, init) that processes each element of the array using the given reducer function fn, starting from an initial value init. This function should accumulate results sequentially and return the final value — implemented without using the built-in Array.reduce() method. 💻 Language Used: JavaScript ❓ Problem Link: https://lnkd.in/gxsp26cz 💡 Solution: https://lnkd.in/giZj_hYw 🧠 Concept Highlighted: This problem deepened my understanding of accumulator functions, data aggregation, and sequential computation in JavaScript. It helped me explore how the powerful reduce() method works behind the scenes — a key tool for transforming and summarizing data efficiently. #Day7 #JavaScript #LeetCode #30DaysOfCode #CodingChallenge #WebDevelopment #FrontendDevelopment #LearningEveryday #ProblemSolving #FunctionalProgramming
To view or add a comment, sign in
-
Today I explored some of the most powerful array methods in JavaScript — map(), filter(), and reduce() ✨ These functions make working with data so much easier and cleaner. 🔹 map() — transforms each element in an array. 🔹 filter() — filters elements based on a condition. 🔹 reduce() — reduces the array to a single value (like sum, average, etc.). While practicing, I understood how combining them can make code much shorter and more readable. Feeling more confident in writing cleaner JavaScript code now! 💻💡 #JavaScript #WebDevelopment #LearningJourney #Coding #FrontendDevelopment #JSMap #Filter #Reduce #Developer
To view or add a comment, sign in
-
🚀 JavaScript Revision Series — Day 3 Today’s revision was all about Operators in JavaScript — the tools that let us do everything from math to logic in our programs! 💻✨ 🟢 Operators Covered: Arithmetic: + - * / % Assignment: =, +=, -=, *= Logical: &&, ||, ! Ternary Operator: condition ? true : false 😄 Fun JS Moment: Remember, 5 + "1" = "51" But 5 - "1" = 4 JS loves to play tricks with operators 😅 --- 🔗 Daily Practice Repo: https://lnkd.in/ejQk84Zg Step by step, one operator at a time — building solid JS foundations! 🚀 #JavaScript #JavaScriptBasics #LearningJourney #WebDevelopment #FrontendDevelopment #CodingJourney #MERNStack #ConsistencyIsKey #SMIT #DeveloperCommunity #Saylani
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development