Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhanghl-k
committed
Mar 12, 2018
1 parent
613e1ae
commit 147d8dd
Showing
7 changed files
with
129 additions
and
30 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,66 @@ | ||
(function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){ | ||
var unique = require('uniq'); | ||
|
||
var data = [1, 2, 2, 3, 4, 5, 5, 5, 6]; | ||
|
||
console.log(unique(data)); | ||
},{"uniq":2}],2:[function(require,module,exports){ | ||
"use strict" | ||
|
||
function unique_pred(list, compare) { | ||
var ptr = 1 | ||
, len = list.length | ||
, a=list[0], b=list[0] | ||
for(var i=1; i<len; ++i) { | ||
b = a | ||
a = list[i] | ||
if(compare(a, b)) { | ||
if(i === ptr) { | ||
ptr++ | ||
continue | ||
} | ||
list[ptr++] = a | ||
} | ||
} | ||
list.length = ptr | ||
return list | ||
} | ||
|
||
function unique_eq(list) { | ||
var ptr = 1 | ||
, len = list.length | ||
, a=list[0], b = list[0] | ||
for(var i=1; i<len; ++i, b=a) { | ||
b = a | ||
a = list[i] | ||
if(a !== b) { | ||
if(i === ptr) { | ||
ptr++ | ||
continue | ||
} | ||
list[ptr++] = a | ||
} | ||
} | ||
list.length = ptr | ||
return list | ||
} | ||
|
||
function unique(list, compare, sorted) { | ||
if(list.length === 0) { | ||
return list | ||
} | ||
if(compare) { | ||
if(!sorted) { | ||
list.sort(compare) | ||
} | ||
return unique_pred(list, compare) | ||
} | ||
if(!sorted) { | ||
list.sort() | ||
} | ||
return unique_eq(list) | ||
} | ||
|
||
module.exports = unique | ||
|
||
},{}]},{},[1]); |
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,24 @@ | ||
<!DOCTYPE html> | ||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> | ||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> | ||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> | ||
<!--[if gt IE 8]><!--> | ||
<html class="no-js"> | ||
<!--<![endif]--> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<title></title> | ||
<meta name="description" content=""> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
</head> | ||
|
||
<body> | ||
<!--[if lt IE 7]> | ||
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p> | ||
<![endif]--> | ||
<script src="bundle-main.js"></script> | ||
</body> | ||
|
||
</html> |
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,5 @@ | ||
var unique = require('uniq'); | ||
|
||
var data = [1, 2, 2, 3, 4, 5, 5, 5, 6]; | ||
|
||
console.log(unique(data)); |
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
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