This file contains hidden or 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
| function fibonacci(num, memo) { | |
| memo = memo || {}; | |
| if (memo[num]) return memo[num]; | |
| if (num <= 1) return 1; | |
| return memo[num] = fibonacci(num - 1, memo) + fibonacci(num - 2, memo); | |
| } |
This file contains hidden or 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
| function fibonacci(num){ | |
| var a = 1, b = 0, temp; | |
| while (num >= 0){ | |
| temp = a; | |
| a = a + b; | |
| b = temp; | |
| num--; | |
| } |
This file contains hidden or 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
| function isPalindrome(str) { | |
| return str === str.split('').reverse().join(''); | |
| } |
This file contains hidden or 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
| #include <nan.h> | |
| using namespace v8; | |
| void IsPalindrome(const FunctionCallbackInfo<Value>& info) { | |
| String::Utf8Value sentence(info[0]->ToString()); | |
| std::string str = std::string(*sentence); | |
| int len = str.length(); | |
| int half = len / 2; | |
| int start = 0; |
This file contains hidden or 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
| var Benchmark = require('benchmark'); | |
| var palindromeC = require('bindings')('palindrome.node'); | |
| var palindromeJs = require('./palindrome.js'); | |
| var suite = new Benchmark.Suite; | |
| var str = 'a man a plan a cat a ham a yak a yam a hat a canal panama'; | |
| suite | |
| .add('Javascript palindrome', function() { | |
| palindromeJs(str); | |
| }) |
This file contains hidden or 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
| function isPalindrome(str) { | |
| var half = Math.round(str.length / 2); | |
| var start = 0; | |
| var end = str.length - 1; | |
| var palindrome = true; | |
| var SPACE = 32; | |
| var COMMA = 44; | |
| var startSpace, endSpace; | |
| while (half && palindrome) { |
This file contains hidden or 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
| #include <nan.h> | |
| using namespace v8; | |
| void IsPalindrome(const FunctionCallbackInfo<Value>& info) { | |
| Nan::Utf8String arg0(info[0]); | |
| char *str = *arg0; | |
| size_t len = arg0.length(); | |
| int half = len / 2; | |
| int start = 0; |
This file contains hidden or 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
| var xhr = new XMLHttpRequest(); | |
| xhr.onreadystatechange = callback; | |
| xhr.open("GET", "https://api.github.com/users/zzarcon"); | |
| xhr.send(); | |
| function callback() { | |
| if (xhr.readyState == 4 && xhr.status == 200) { | |
| var json = JSON.parse(xhr.responseText); | |
This file contains hidden or 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
| $.get('https://api.github.com/users/zzarcon', callback); | |
| function callback(user) { | |
| console.log(user.name) | |
| } |
This file contains hidden or 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
| function xhrPromise() { | |
| return new Promise(function(resolve, eject) { | |
| var xhr = new XMLHttpRequest(); | |
| xhr.onreadystatechange = onready; | |
| xhr.open("GET", "https://api.github.com/users/zzarcon"); | |
| xhr.send(); | |
| function onready() { | |
| if (xhr.readyState == 4 && xhr.status == 200) { |