Skip to content

Instantly share code, notes, and snippets.

View dmoptimal's full-sized avatar

Daniel Mason dmoptimal

View GitHub Profile
@ljharb
ljharb / array_iteration_thoughts.md
Last active July 27, 2024 16:17
Array iteration methods summarized

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu

import platform = require('platform');
import color = require('color');
import app = require('application');
declare var android: any;
export function onPageLoaded () {
const View = android.view.View;
if (app.android && platform.device.sdkVersion >= '21') {
let LayoutParams = <any>android.view.WindowManager.LayoutParams;
@shiv19
shiv19 / gradientActionbarIosNativeScript.js
Last active April 17, 2021 09:21
use this code with loaded event of a page to get gradient actionbar on iOS for NativeScript Apps
import { Frame } from '@nativescript/core/ui/frame';
import { Color } from '@nativescript/core/color';
import { isIOS } from '@nativescript/core/platform';
/*
// Legacy require statements if using Vanilla {N}
const Frame = require('@nativescript/core/ui/frame').Frame;
const Color = require('@nativescript/core/color').Color;
const isIOS = require('@nativescript/core/platform').isIOS;
*/