superset-fun
v1.1.5
Published
The `superset-fun` repository is a collection of various fun and interesting concepts in programming. From exploring asynchronous loops to experimenting with different data structures, this repository aims to provide engaging and educational content for d
Downloads
8
Maintainers
Readme
Superset-fun
The superset-fun
repository is a collection of various fun and interesting concepts in programming. From exploring asynchronous loops to experimenting with different data structures, this repository aims to provide engaging and educational content for developers of all skill levels.
Contents
- Asynchronous Loop Examples: Dive into the world of asynchronous programming with examples demonstrating how to loop through arrays, objects, and strings asynchronously using the
loop
function. - Standard Loop Examples: Compare and contrast asynchronous loop examples with traditional synchronous loop implementations to better understand the differences and benefits of each approach.
- Fun Programming Challenges: Challenge yourself with fun programming exercises and puzzles designed to test your problem-solving skills and creativity.
- Interactive Demos: Explore interactive demos and visualizations that illustrate various programming concepts in a fun and interactive way.
Purpose
The superset-fun
repository serves as a playground for developers to experiment with new ideas, learn new concepts, and share their experiences with the programming community. Whether you're a beginner looking to learn the basics or an experienced developer seeking inspiration, there's something for everyone in this repository.
Asynchronous Loop Examples
This repository contains examples of asynchronous loops using the loop
function. Each example demonstrates different use cases for looping with asynchronous operations.
Loop with Limit Number
loop(5, async x => {
console.log('x:', x)
await hold(500)
})
This example demonstrates a standard loop with a limit number. It logs the value of x asynchronously with a delay of 500 milliseconds.
Loop an Array
loop([5, 4, 3, 2, 1], async (n, index) => {
console.log('n:', n, index)
await hold(500)
})
This example demonstrates looping over an array using the loop function. It logs the value of each element along with its index asynchronously.
Loop an Object
loop({ one: 1, two: 2, three: 3 }, async (key, value) => {
console.log(key, ':', value)
await hold(500)
})
This example demonstrates looping over an object using the loop function. It logs the key-value pairs of the object asynchronously.
Loop a String
loop('Lorem ipsum', async (letter, index) => {
process.stdout.write(letter)
await hold(10)
})
This example demonstrates looping over a string using the loop function. It prints each letter of the string asynchronously with a delay of 10 milliseconds.
Async/Await Example
const data = [
{ name: 'Naruto', clan: 'Uzumaki', children: ['Boruto', 'Himawari'] },
{ name: 'Sasuke', clan: 'Uchiha', children: ['Sarada'] }
]
loop(data, async (data, index) => {
console.log('index', ' :', index)
await loop(data, async (key, val) => {
if ( key != 'children' ) console.log(key, ' :', val)
else await loop(val, async (data, index) => {
console.log('children :', data)
})
})
console.log('-----------------------------------------------')
}).then(_ => {
console.log('Finished')
})
Standard Loop Examples
// Standard loop: for ( let x = 0; x < 5; x++ )
for (let x = 0; x < 5; x++) {
console.log('x:', x);
}
// Standard loop: for ( let [x, n] of [5, 4, 3, 2, 1].entries() )
for (let [x, n] of [5, 4, 3, 2, 1].entries()) {
console.log('n:', n, x);
}
// Standard loop: for ( let [key, val] of Object.entries({ one: 1, two: 2, three: 3 }) )
for (let [key, val] of Object.entries({ one: 1, two: 2, three: 3 })) {
console.log(key, ':', val);
}
// Standard loop: for ( let char of 'Lorem ipsum' )
for (let char of 'Lorem ipsum') {
console.log(char);
}
This section provides examples of standard loops for comparison with the asynchronous loop examples. This example demonstrates using async/await within a loop to process nested data structures asynchronously.
Contributions
Contributions to the superset-fun
repository are welcome! If you have an interesting programming concept, a fun challenge, or an interactive demo to share, feel free to submit a pull request. Let's make learning and exploring programming fun together!