- Daily Sandbox
- Posts
- Daily Digest: Use apply() like a Pro
Daily Digest: Use apply() like a Pro
Daily Issue #6
🎆 NEWS, INNOVATIONS, TRENDS
How to move from hard-coded code for each environment to a Envless application in Angular
How To Add Pagination To Your Nextjs Web Application
No matter how long I have been using JavaScript, some its fundamental features always get my attention, this time it’s all about how to use the apply() method Like a pro
15 Useful CSS Properties You Should Know About
When it comes to Git, especially command-line, it always seems like some magic happens behind the scenes. Here are some modern commands and features you should be using.
🧰 CODING TOOLBOX
Torchchat is a lightweight codebase demonstrating the seamless operation of large language models (LLMs)
An IDE called Wordware that empowers users to rapidly develop AI Agents and applications
Dodo is an AI Receptionist for Veterinarians
Free AI Translator Online
#️⃣ DO YOU AI PROMPT?
Job Interview Trainer
I’d like you to act and respond as my Expert Job Interview Coach.
I’m going to provide you with information in the form of my resume, my [LinkedIn profile], as well as [job descriptions] for the jobs that I’m looking for.
I’d then like your help coaching me to be prepared for my upcoming job interview at [COMPANY] for the role of [ROLE]
💻 CODE SNIPPETS
Problem: I was developing a method that, given a list of school levels, would group consecutive numbers into ranges. For example, a list like KG, 1, 2, 3, 6, 7, 8 should be grouped as KG, 1-3, 6-8.
Solution: The code below does just that :)
function formatSchoolLevels(levelsStr) {
const levels = levelsStr.split(',');
// Separate numeric and non-numeric levels
const numericLevels = levels.filter(level => /^\d+$/.test(level)).sort((a, b) => a - b);
const nonNumericLevels = levels.filter(level => !/^\d+$/.test(level));
// Group consecutive numbers into ranges
const groupedNumericLevels = [];
let currentGroup = [];
numericLevels.forEach((level, index) => {
if (currentGroup.length === 0) {
currentGroup.push(level);
} else {
const lastElement = currentGroup[currentGroup.length - 1];
if (parseInt(level, 10) === parseInt(lastElement, 10) + 1) {
currentGroup.push(level);
} else {
if (currentGroup.length > 1) {
groupedNumericLevels.push(`${currentGroup[0]}-${currentGroup[currentGroup.length - 1]}`);
} else {
groupedNumericLevels.push(currentGroup[0]);
}
currentGroup = [level];
}
}
// Check if this is the last element
if (index === numericLevels.length - 1) {
if (currentGroup.length > 1) {
groupedNumericLevels.push(`${currentGroup[0]}-${currentGroup[currentGroup.length - 1]}`);
} else {
groupedNumericLevels.push(currentGroup[0]);
}
}
});
// Combine non-numeric and numeric levels to ensure non-numeric values are first
const combinedLevels = nonNumericLevels.concat(groupedNumericLevels);
// Join all parts back into a single string with comma separation
return combinedLevels.join(', ');
}
console.log(formatSchoolLevels("KG,1,2,3,4,5,6,7,8"));
console.log(formatSchoolLevels("KG,1,2,3,10,11,12"));
console.log(formatSchoolLevels("KG,Pre-K,1,2,3,5,6,8"));
🛠️ SUGGEST A TOOL
If you have built anything that you’d like to share with the community, get with me on X @dailysandbox_ 😀
Curious about this email? That means that at some point you must have subscribed, likely at cogency.io
Reply