tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
15
Task/Run-length-encoding/JavaScript/run-length-encoding-1.js
Normal file
15
Task/Run-length-encoding/JavaScript/run-length-encoding-1.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
function encode(input) {
|
||||
var encoding = [];
|
||||
var prev, count, i;
|
||||
for (count = 1, prev = input[0], i = 1; i < input.length; i++) {
|
||||
if (input[i] != prev) {
|
||||
encoding.push([count, prev]);
|
||||
count = 1;
|
||||
prev = input[i];
|
||||
}
|
||||
else
|
||||
count ++;
|
||||
}
|
||||
encoding.push([count, prev]);
|
||||
return encoding;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue