Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
function allEqual(a) {
|
||||
var out = true, i = 0;
|
||||
while (++i<a.length) {
|
||||
out = out && (a[i-1] === a[i]);
|
||||
} return out;
|
||||
}
|
||||
|
||||
function azSorted(a) {
|
||||
var out = true, i = 0;
|
||||
while (++i<a.length) {
|
||||
out = out && (a[i-1] < a[i]);
|
||||
} return out;
|
||||
}
|
||||
|
||||
var e = ['AA', 'AA', 'AA', 'AA'], s = ['AA', 'ACB', 'BB', 'CC'], empty = [], single = ['AA'];
|
||||
console.log(allEqual(e)); // true
|
||||
console.log(allEqual(s)); // false
|
||||
console.log(allEqual(empty)); // true
|
||||
console.log(allEqual(single)); // true
|
||||
console.log(azSorted(e)); // false
|
||||
console.log(azSorted(s)); // true
|
||||
console.log(azSorted(empty)); // true
|
||||
console.log(azSorted(single)); // true
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
// allEqual :: [String] -> Bool
|
||||
let allEqual = xs => and(zipWith(equal, xs, xs.slice(1))),
|
||||
|
||||
// azSorted :: [String] -> Bool
|
||||
azSorted = xs => and(zipWith(azBefore, xs, xs.slice(1))),
|
||||
|
||||
// equal :: a -> a -> Bool
|
||||
equal = (a, b) => a === b,
|
||||
|
||||
// azBefore :: String -> String -> Bool
|
||||
azBefore = (a, b) => a.toLowerCase() <= b.toLowerCase();
|
||||
|
||||
|
||||
// GENERIC
|
||||
|
||||
// and :: [Bool] -> Bool
|
||||
let and = xs => xs.reduceRight((a, x) => a && x, true),
|
||||
|
||||
// zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
|
||||
zipWith = (f, xs, ys) => {
|
||||
let ny = ys.length;
|
||||
return (xs.length <= ny ? xs : xs.slice(0, ny))
|
||||
.map((x, i) => f(x, ys[i]));
|
||||
};
|
||||
|
||||
|
||||
// TEST
|
||||
|
||||
let lists = [
|
||||
['isiZulu', 'isiXhosa', 'isiNdebele', 'Xitsonga',
|
||||
'Tshivenda', 'Setswana', 'Sesotho sa Leboa', 'Sesotho',
|
||||
'English', 'Afrikaans'
|
||||
],
|
||||
['Afrikaans', 'English', 'isiNdebele', 'isiXhosa',
|
||||
'isiZulu', 'Sesotho', 'Sesotho sa Leboa', 'Setswana',
|
||||
'Tshivenda', 'Xitsonga',
|
||||
],
|
||||
['alpha', 'alpha', 'alpha', 'alpha', 'alpha', 'alpha',
|
||||
'alpha', 'alpha', 'alpha', 'alpha', 'alpha', 'alpha'
|
||||
]
|
||||
];
|
||||
|
||||
return {
|
||||
allEqual: lists.map(allEqual),
|
||||
azSorted: lists.map(azSorted)
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"allEqual": [
|
||||
false,
|
||||
false,
|
||||
true
|
||||
],
|
||||
"azSorted": [
|
||||
false,
|
||||
true,
|
||||
true
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue