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

Commit c426eec

Browse files
author
munnaSorder
committed
add few function
1 parent d1ead93 commit c426eec

File tree

7 files changed

+97
-0
lines changed

7 files changed

+97
-0
lines changed

‎concat.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// example 1
2+
function concatExOne(arr, ...items) {
3+
for (let i = 0, length = items.length; i < length; i++) {
4+
if(Array.isArray(items[i])) arr.push(...items[i]);
5+
else arr.push(items[i]);
6+
}
7+
return arr;
8+
}
9+
10+
// console.log(concatExOne([1,2,3], 11,22,33,[111,[1111]]));
11+
12+
// example 2
13+
function concatExTwo(arr, ...items) {
14+
return [...arr, ...items.flat()]
15+
}
16+
17+
// console.log(concatExTwo([1,2,3], 11,22,33,[111,[1111]]));
18+
console.dir(Array.prototype)

‎every.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const myArray = [1,2,3];
2+
3+
function every(arr, cb) {
4+
for (let i = 0; i < arr.length; i++) {
5+
if (!cb(arr[i], i, arr)) return false;
6+
}
7+
return true
8+
}
9+
const result = every(myArray, (doc) => doc > 0)
10+
console.log(result)

‎includes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const myArray = [1,2,3]
2+
3+
function includes(arr, searchElement, formIndex = 0) {
4+
for (let i = formIndex; i < arr.length; i++) {
5+
if (arr[i] === searchElement) return true;
6+
}
7+
return false;
8+
}
9+
10+
console.log(includes(myArray, 5))

‎index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
<h1>Programming is to thinking not typing....</h1>
11+
12+
<script src="./push.js"></script>
13+
</body>
14+
</html>

‎lastIndexOf.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const myString = 'Hello World';
2+
3+
4+
5+
function lastIndexOf(arr, str, searchElement = 0) {
6+
7+
let newString = arr.split(' ');
8+
const findWord = newString.find(doc => doc === str)
9+
10+
for (let i = searchElement; i < arr.length; i++){
11+
if (str.length > 1) {
12+
if (findWord === str) {
13+
if (arr[i] === (str.charAt())) return i;
14+
} else {
15+
return -1;
16+
}
17+
} else {
18+
if(arr[i] === str) return i;
19+
}
20+
}
21+
return -1;
22+
}
23+
console.log(lastIndexOf(myString, 'World'))

‎push.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let newArray = [];
2+
function push(arr, ...items) {
3+
for (let i = 0; i < items.length; i++) {
4+
console.log('top', arr.length)
5+
arr[arr.length] = items[i]
6+
console.log('down',arr.length)
7+
}
8+
return arr.length;
9+
}
10+
11+
push(newArray, 1,2,3,4);
12+
console.log(newArray)

‎some.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const myArray = [1,2,3];
2+
3+
function some(arr, cb) {
4+
for(let i = 0; i < arr.length; i++) {
5+
if (cb(arr[i], i, arr)) return true;
6+
}
7+
return false;
8+
}
9+
10+
console.log(some(myArray, doc => doc > 2))

0 commit comments

Comments
(0)

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