https://github.com/aymen94/js-solving-problem
javascript function for solving problem
https://github.com/aymen94/js-solving-problem
Last synced: 4 months ago
JSON representation
javascript function for solving problem
- Host: GitHub
- URL: https://github.com/aymen94/js-solving-problem
- Owner: aymen94
- Created: 2017-09-08T12:59:47.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-08T13:35:56.000Z (over 7 years ago)
- Last Synced: 2025-01-02T15:28:19.408Z (5 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JS-solving-problem
javascript function for solving problem## Create new Array with single item of the previous array (arraySaveSingleItem.js)
* exemple A=[1,9,2,1,6,2,7,9,6,5,4,7]
* Sort A=[ 1, 1, 2, 2, 4, 5, 6, 6, 7, 7, 9, 9 ]
* return [4,5]
### CODE:
```
function arraySingleItem(A) {
A=A.sort()
var newA=[];
A.forEach((v,i,a)=>{
if(v==a[i+1] || v==a[i-1])
return;
else
newA.push(v);
})
return newA;
}
```## Remove Dupticate From Array (arrayRemoveDuplicate.js)
* exmple N=[1,9,2,1,6,2,7,9,6,5,4,7];
* after N=[1,9,2,6,7,5,4]
### CODE:
```
function removeDuplicate(N){
N=N.filter((v,i,a) => a.indexOf(v)==i)
return N;
}
```