-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build Scripts Updated to break on Error
- Loading branch information
1 parent
f02433b
commit 1eb0782
Showing
2 changed files
with
81 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const compressArray = original => { | ||
var compressed = [] | ||
// make a copy of the input array | ||
var copy = original.slice(0) | ||
|
||
// first loop goes over every element | ||
for (var i = 0; i < original.length; i++) { | ||
var myCount = 0 | ||
// loop over every element in the copy and see if it's the same | ||
for (var w = 0; w < copy.length; w++) { | ||
if (original[i] == copy[w]) { | ||
// increase amount of times duplicate is found | ||
myCount++ | ||
// sets item to undefined | ||
delete copy[w] | ||
} | ||
} | ||
|
||
if (myCount > 0) { | ||
var a = new Object() | ||
a.value = original[i] | ||
a.count = myCount | ||
compressed.push(a) | ||
} | ||
} | ||
|
||
return compressed | ||
} | ||
|
||
module.exports = compressArray |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters