how do i pair of socks in an array javascript
function sortAndCount( n, arr ) {
let sorted = arr.sort( (a,b) => a - b);
let pairs = 0;
for (let i = 0; i < n - 1; i++) {
if ( sorted[i] === sorted[i + 1]) {
pairs++;
i += 1;
}
}
return pairs;
}
Also in JavaScript:
- passing a variable to the width style div angular
- jquery check checkbox
- target all element besides the clicked one
- js string template decimals
- how to draw a flower in javascript
- beautify json python
- how to write img jsx
- event loop in javascript
- not equal to sign in js
- How can I upload files asynchronously
- sleeping in js
- discord js check every x minutes
- check equality numbers javascript
- array.filter in js
- react native side drawer
- remove array elements javascript
- .push js
- select a form by name jquery
- how to create array in javascript
- javascript detect touch
- ajax datatable reload paging retained
- get started with react native
- chartjs lineTension
- the red validation class doesn't apply on jquery