Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A focused JavaScript repository dedicated to strengthening logic-building and problem-solving skills. It contains concise, well-structured solutions to common programming challenges, covering core concepts such as loops, conditionals, arrays, objects, functions, and basic algorithms. The goal is to build a strong foundation in JavaScript.

Notifications You must be signed in to change notification settings

Rajeevkumar69/JavaScript-logic-building

Repository files navigation

# JavaScript Array HOF
```js
const users = [
 { name: 'A', age: 24, role: 'admin' },
 { name: 'B', age: 20, role: 'user' },
 { name: 'A', age: 30, role: 'user' }
];

1. filter():- Returns: Array , many data

Q. : "Give me ALL matching items"

const result = users.filter(user => user.name === 'A');

2. find():- One object OR undefined

Q. : "Give me FIRST matching item"

const result = users.find(user => user.name === 'A');

forEach is NOT for data transformation. forEach is for SIDE EFFECTS. forEach → change EXISTING data map → create NEW data


3. map():- Array

Q. : "Change data, same length"

const result = users.map(user => user.name = 'ChangeName');

4. forEach():- Nothing

Q. : "Just do something, don’t return"

const names = [];
users.forEach(user => {
 names.push(user.name);
});
users.forEach(user => {
 user.isActive = true;
});

5. some():- boolean

Q. : "Is there AT LEAST ONE?"

const result = users.some(user => user.age > 25);

6. every(): boolean

Q. : "Are ALL matching?"

const result = users.every(user => user.age > 18);

7. reduce():- Anything

Returns: Q. : "Combine everything into one"

const totalAge = users.reduce((sum, user) => {
 return sum + user.age;
}, 0);

8. sort():- Array (same one, modified)

Q. : "Order the data"

users.sort((a, b) => a.age - b.age);

Super Easy Memory Line (Read Daily)

filter → many 
find → one 
map → change 
forEach → nothing 
some → any 
every → all 
reduce → combine 
sort → order

About

A focused JavaScript repository dedicated to strengthening logic-building and problem-solving skills. It contains concise, well-structured solutions to common programming challenges, covering core concepts such as loops, conditionals, arrays, objects, functions, and basic algorithms. The goal is to build a strong foundation in JavaScript.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /