Skip to content

Instantly share code, notes, and snippets.

View alejandrolechuga's full-sized avatar
🤯
Focusing

neptuno alejandrolechuga

🤯
Focusing
View GitHub Profile
/**
The data comes from an API endpoint,
“https://disney-api.com/characters/movies”,
which returns a list of all the characters
and a list of the cartoons they appear in.
{ “Mickey Mouse”: [ “Steamboat Willie”, “Plane Crazy”, “The Barn Dance”, … ], “Minnie Mouse”: [ … ], “Stitch”: […],… }
//////////////////////////////////////////////////////////////
//
// Question 3:
//
// Implement a basic calculator to evaluate a simple expression string.
//
// The expression string may contain the plus +, minus sign -,
// non-negative integers and empty spaces.
//
// You may assume that the given expression is always valid.
/**
Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array.
Example
For sequence = [1, 3, 2, 1], the output should be
almostIncreasingSequence(sequence) = false;
There is no one element in this array that can be removed in order to get a strictly increasing sequence.
// find min and max within an array
var array = [3,4,5,12,90,23];
// function findMM(a) {
// var min = a[0], max = min;
// for (var i = 2, length = a.length; i < length; i ++) {
// if (a[i] > max) {
// max = a[i];
// } else if (a[i] < min) {
// min = a[i];
// }
@alejandrolechuga
alejandrolechuga / index.html
Created May 22, 2017 12:46
Angular 1.x TodoApp
<!DOCTYPE html>
<html ng-app="todoApp">
<head >
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<style>
body {
var primes = [2, 3, 5, 7, 11, 13, 17];
var nonprimes = [4, 6, 8, 9];
// 1 or itself
// is prime number ?
function isPrime(n) {
if (n === 0) return false;
var limit = Math.round(Math.sqrt(n));
for (var i = 2; i <= limit; i++) {
if (n % i === 0) return false;
}
var ejemplos = [
{source:'RX', result: false}, // => false
{source:'WSWSR', result: 'WSRSW'}, // => 'WSRSW'
{source:'WSWSRG', result: false}, // => false
{source:'WSWS', result: 'WSSW'}, // => 'WSSW'
{source:'WSWSS', result: 'WSSSW'}, // => 'WSSSW'
{source:'X', result: 'X'}, // => 'X'
{source:'AA', result: 'AA'}, // => 'AA'
{source:'XAA' , result: 'AXA'}, // => 'AXA'
{source:'OMSSO', result: 'OSMSO'} // => 'OSMSO'
var example1 = 'camelCase';
// ['camel', 'Case']
var example2 = 'happyHolidaysDude';
// ['happy', 'Holiday', 'Dude']
var example3 = 'tTYL';
// ['t', 'T', 'Y', 'L']
var example4 = 'NASA';
// ['N', 'A', 'S', 'A']
var example5 = 'Nasa';
// ['Nasa']
// Array flatten Technique
var oneDepth = [[1], [2], [3], [4], [6], 7, 8];
var multiDepth = [[1, [2, 3], [4]], [5], [3, [4, 5]], [6], [7], 7, [[[[[8]]]]]];
// flatten one level
// function flattenOneLevel(array) {
// var results = [];
// for (var i = 0; i < array.length; i++) {
// if (Array.isArray(array[i])) {
// Array.concat
var array = [1, 2].concat([3, 4]);
// push
array = array.concat(5);
// unshift
array = [0].concat(array);