2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,12 +1,11 @@
|
|||
function is_pangram(str) {
|
||||
var s = str.toLowerCase();
|
||||
function isPangram(s) {
|
||||
var letters = "zqxjkvbpygfwmucldrhsnioate"
|
||||
// sorted by frequency ascending (http://en.wikipedia.org/wiki/Letter_frequency)
|
||||
var letters = "zqxjkvbpygfwmucldrhsnioate";
|
||||
s = s.toLowerCase().replace(/[^a-z]/g,'')
|
||||
for (var i = 0; i < 26; i++)
|
||||
if (s.indexOf(letters.charAt(i)) == -1)
|
||||
return false;
|
||||
return true;
|
||||
if (s.indexOf(letters[i]) < 0) return false
|
||||
return true
|
||||
}
|
||||
|
||||
print(is_pangram("is this a pangram")); // false
|
||||
print(is_pangram("The quick brown fox jumps over the lazy dog")); // true
|
||||
console.log(isPangram("is this a pangram")) // false
|
||||
console.log(isPangram("The quick brown fox jumps over the lazy dog")) // true
|
||||
|
|
|
|||
|
|
@ -1,36 +1,20 @@
|
|||
var _ = require("underscore");
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
// Curried mixin function
|
||||
// Utility Methods
|
||||
_.mixin({
|
||||
checkAToZ: function(s) {
|
||||
return function(letter) {
|
||||
if (s.indexOf(letter) != -1) { return true};
|
||||
}
|
||||
}
|
||||
});
|
||||
// isPangram :: String -> Bool
|
||||
let isPangram = s => {
|
||||
let lc = s.toLowerCase();
|
||||
|
||||
_.mixin({
|
||||
toLower: function(str) {
|
||||
return str.toLowerCase();
|
||||
}
|
||||
});
|
||||
return 'abcdefghijklmnopqrstuvwxyz'
|
||||
.split('')
|
||||
.filter(c => lc.indexOf(c) === -1)
|
||||
.length === 0;
|
||||
};
|
||||
|
||||
_.mixin({
|
||||
isPangram: function(lstr) {
|
||||
var letters = "zqxjkvbpygfwmucldrhsnioate".split('');
|
||||
return _.every(letters, _.checkAToZ(lstr));
|
||||
}
|
||||
});
|
||||
// TEST
|
||||
return [
|
||||
'is this a pangram',
|
||||
'The quick brown fox jumps over the lazy dog'
|
||||
].map(isPangram);
|
||||
|
||||
|
||||
var panGramStr = "The quick brown fox jumps over the lazy dog";
|
||||
var IsPanGram = function(panGramStr) {
|
||||
return _.chain(panGramStr).toLower().isPangram().value();
|
||||
};
|
||||
|
||||
console.log("Result IsPanGram - \"", panGramStr,"\" - " , IsPanGram.call(this,panGramStr));
|
||||
console.log("Result IsPanGram - \"", "the World","\" - ", IsPanGram.call(this, "the World"));
|
||||
|
||||
// Result IsPanGram - " The quick brown fox jumps over the lazy dog " - true
|
||||
// Result IsPanGram - " the World " - false
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue