How to use indexPath method in Best

Best JavaScript code snippet using best

builder.js

Source:builder.js Github

copy

Full Screen

1var dataManager = require("./data-manager");2var helper = require("./helper");3var textItems = dataManager.getTextItems();4var actionItems = dataManager.getActionItems();5function createClipboardView() {6 return {7 type: "list",8 props: {9 id: "clipboard-list",10 reorder: true,11 rowHeight: $app.env == $env.today ? 36 : 44,12 separatorColor: $app.env == $env.today ? $rgba(100, 100, 100, 0.25) : $color("separator"),13 data: textItems,14 actions: [15 {16 title: "delete",17 handler: function(sender, indexPath) {18 if (textItems[indexPath.row] === $clipboard.text) {19 $clipboard.text = "";20 }21 helper.arrayRemove(textItems, indexPath.row);22 saveTextItems();23 reloadTextItems();24 }25 },26 {27 title: $l10n("EDIT"),28 handler: function(sender, indexPath) {29 $input.text({30 text: textItems[indexPath.row]31 }).then(function(text) {32 if (text.length > 0) {33 textItems[indexPath.row] = text;34 sender.data = textItems;35 saveTextItems();36 }37 });38 }39 },40 {41 title: $l10n("SEARCH"),42 handler: function(sender, indexPath) {43 helper.searchText(textItems[indexPath.row]);44 }45 }46 ]47 },48 layout: listViewLayout(),49 events: {50 didSelect: function(sender, indexPath, object) {51 $clipboard.text = object;52 $ui.toast($l10n("COPIED"));53 $device.taptic(1);54 },55 reorderMoved: function(fromIndexPath, toIndexPath) {56 helper.arrayMove(textItems, fromIndexPath.row, toIndexPath.row);57 },58 reorderFinished: function() {59 saveTextItems();60 }61 }62 }63}64function saveTextItems() {65 dataManager.setTextItems(textItems);66}67function reloadTextItems() {68 textItems = dataManager.getTextItems();69}70function editAction(action, indexPath) {71 var creator = require("./action-creator");72 creator.edit(action, function(action) {73 actionItems[indexPath.row] = action;74 $("action-list").data = mapActionItems();75 saveActionItems();76 });77}78function saveActionItems() {79 dataManager.setActionItems(actionItems);80}81function reloadActionItems() {82 actionItems = dataManager.getActionItems();83}84function createActionView() {85 return {86 type: "list",87 props: {88 id: "action-list",89 rowHeight: 64,90 reorder: true,91 actions: [92 {93 title: "delete",94 handler: function(sender, indexPath) {95 helper.arrayRemove(actionItems, indexPath.row);96 saveActionItems();97 }98 },99 {100 title: $l10n("LAUNCH"),101 handler: function(sender, indexPath) {102 helper.runAction(actionItems[indexPath.row]);103 }104 },105 {106 title: $l10n("MAKE_ICON"),107 handler: function(sender, indexPath) {108 makeHomeIcon(actionItems[indexPath.row]);109 }110 }111 ],112 template: {113 views: [114 {115 type: "label",116 props: {117 id: "action-name-label"118 },119 layout: function(make, view) {120 make.top.inset(10);121 make.left.inset(15);122 }123 },124 {125 type: "label",126 props: {127 id: "action-pattern-label"128 },129 layout: function(make, view) {130 make.bottom.inset(8);131 make.left.inset(15);132 make.right.inset(72);133 }134 },135 {136 type: "image",137 props: {138 id: "action-icon-image",139 bgcolor: $color("clear")140 },141 layout: function(make, view) {142 make.centerY.equalTo(view.super);143 make.right.inset(15);144 make.size.equalTo($size(24, 24));145 }146 }147 ]148 },149 data: mapActionItems()150 },151 layout: listViewLayout(),152 events: {153 didSelect: function(sender, indexPath) {154 var action = actionItems[indexPath.row];155 editAction(action, indexPath);156 },157 reorderMoved: function(fromIndexPath, toIndexPath) {158 helper.arrayMove(actionItems, fromIndexPath.row, toIndexPath.row);159 },160 reorderFinished: function() {161 saveActionItems();162 }163 }164 }165}166function createActionItem(item) {167 return {168 "action-name-label": {169 "text": item.name170 },171 "action-pattern-label": {172 "text": item.pattern173 },174 "action-icon-image": {175 "icon": $icon(item.icon)176 }177 };178}179function mapActionItems() {180 return actionItems.map(function(item) {181 return createActionItem(item);182 });183}184function listViewLayout() {185 return function(make, view) {186 make.left.right.equalTo(0);187 make.top.inset(44);188 make.bottom.inset($app.env == $env.today ? 44 : 52);189 }190}191function makeHomeIcon(action) {192 var options = [$l10n("USE_DEFAULT_ICON"), $l10n("PHOTO_LIBRARY")];193 $ui.menu(options).then(function(selected) {194 if (selected == null) {195 return;196 }197 if (selected.index == 0) {198 var icon = helper.makeIcon(action.icon, $color("tint"));199 createHomeShortcut(action, icon);200 } else {201 $photo.pick().then(function(result) {202 if (result && result.image) {203 createHomeShortcut(action, result.image);204 }205 });206 }207 });208}209function createHomeShortcut(action, icon) {210 $system.makeIcon({211 title: action.name,212 url: action.pattern.replace("%@", ""),213 icon: icon214 });215}216module.exports = {217 createClipboardView: createClipboardView,218 createActionView: createActionView, 219 reloadTextItems: reloadTextItems,220 createActionItem: createActionItem,221 reloadActionItems: reloadActionItems,...

Full Screen

Full Screen

ObservableTreeList.ts

Source:ObservableTreeList.ts Github

copy

Full Screen

1import { EventEmitter } from 'cellx';2const ERROR_INDEXPATH_EMPTY = 'Indexpath cannot be empty';3export interface IItem {4 [name: string]: any;5 parent?: IItem | null;6 children?: Array<IItem>;7}8export function setParent<T extends IItem>(items: Array<T>, parent: T | null = null): Array<T> {9 for (let item of items) {10 item.parent = parent;11 setParent(item.children!, item);12 }13 return items;14}15export class ObservableTreeList<T extends IItem = IItem> extends EventEmitter {16 static EVENT_CHANGE = 'change';17 _items: Array<T>;18 get length() {19 return this._items.length;20 }21 constructor(items?: Array<T>) {22 super();23 this._items = items24 ? setParent(25 items.map(function _(item): T {26 return {27 ...item,28 children: item.children ? item.children.map(_) : []29 };30 })31 )32 : [];33 }34 get(indexpath: Array<number> | number) {35 if (typeof indexpath == 'number') {36 return this._items[indexpath];37 }38 if (!indexpath.length) {39 throw new TypeError(ERROR_INDEXPATH_EMPTY);40 }41 let item: IItem | undefined = this._items[indexpath[0]];42 for (let i = 1, l = indexpath.length; item && i < l; i++) {43 item = item.children && item.children[indexpath[i]];44 }45 return item as T | undefined;46 }47 set(indexpath: Array<number> | number, item: T) {48 let items: Array<IItem> | undefined;49 let parent: IItem | undefined;50 let index: number;51 if (typeof indexpath == 'number') {52 items = this._items;53 index = indexpath;54 } else {55 let indexpathLength = indexpath.length;56 if (!indexpathLength) {57 throw new TypeError(ERROR_INDEXPATH_EMPTY);58 }59 if (indexpathLength == 1) {60 items = this._items;61 } else {62 let node: IItem | undefined = this._items[indexpath[0]];63 for (let i = 1, l = indexpathLength - 1; node && i < l; i++) {64 node = node.children && node.children[indexpath[i]];65 }66 if (!node) {67 throw new TypeError(68 `Item by indexpath "[${indexpath.slice(0, -1).join(',')}]" is not exist`69 );70 }71 items = node.children || (node.children = []);72 parent = node;73 }74 index = indexpath[indexpathLength - 1];75 }76 if (index > items.length) {77 throw new RangeError('Index out of valid range');78 }79 if (item !== items[index]) {80 if (parent) {81 item.parent = parent;82 }83 items[index] = item;84 this.emit(ObservableTreeList.EVENT_CHANGE);85 }86 return this;87 }88 forEach(89 callback: (item: T, index: number, list: ObservableTreeList<T>) => void,90 context?: any91 ) {}92 map<R = any>(93 callback: (item: T, index: number, list: ObservableTreeList<T>) => any,94 context?: any95 ): Array<R> {96 return 0 as any;97 }98 filter(99 callback: (item: T, index: number, list: ObservableTreeList<T>) => boolean | void,100 context?: any101 ): Array<T> {102 return 0 as any;103 }104 every(105 callback: (item: T, index: number, list: ObservableTreeList<T>) => boolean | void,106 context?: any107 ): boolean {108 return 0 as any;109 }110 some(111 callback: (item: T, index: number, list: ObservableTreeList<T>) => boolean | void,112 context?: any113 ): boolean {114 return 0 as any;115 }116 reduce<R>(117 callback: (accumulator: R, item: T, index: number, list: ObservableTreeList<T>) => R,118 initialValue?: R119 ): R {120 return 0 as any;121 }122 reduceRight<R>(123 callback: (accumulator: R, item: T, index: number, list: ObservableTreeList<T>) => R,124 initialValue?: R125 ): any {126 return 0 as any;127 }128 toArray(): Array<T> {129 return this._items.slice();130 }131}132for (let name of ['forEach', 'map', 'filter', 'every', 'some']) {133 ObservableTreeList.prototype[name] = function (callback: any, context: any) {134 return this._items[name](function (this: any, item: any, index: any) {135 return callback.call(context, item, index, this);136 }, this);137 };138}139for (let name of ['reduce', 'reduceRight']) {140 ObservableTreeList.prototype[name] = function (callback: any, initialValue: any) {141 let items = this._items;142 let list = this;143 function wrapper(accumulator: any, item: any, index: any) {144 return callback(accumulator, item, index, list);145 }146 return arguments.length >= 2 ? items[name](wrapper, initialValue) : items[name](wrapper);147 };...

Full Screen

Full Screen

select.service.ts

Source:select.service.ts Github

copy

Full Screen

1import React from 'react';2import { IndexPath } from '../../devsupport';3import { SelectItemElement } from './selectItem.component';4export interface SelectItemDescriptor {5 multiSelect: boolean;6 index: IndexPath;7 groupIndices?: IndexPath[];8}9const SEPARATOR: string = ', ';10export class SelectService {11 public selectItem = (multiSelect: boolean,12 descriptor: SelectItemDescriptor,13 selected: IndexPath[]): IndexPath | IndexPath[] => {14 if (multiSelect) {15 return this.createMultiSelectIndices(descriptor, selected);16 }17 return descriptor.index;18 };19 public toStringSelected = (selected: IndexPath[]): string => {20 if (!Array.isArray(selected)) {21 return '';22 }23 const options: string[] = selected.map((index: IndexPath): string => {24 return `Option ${index.toString()}`;25 });26 return options.join(SEPARATOR);27 };28 public isSelected = (descriptor: SelectItemDescriptor, selected: IndexPath[]): boolean => {29 if (descriptor.multiSelect && this.isGroup(descriptor)) {30 return this.containsSomeFromGroup(descriptor.index, selected);31 }32 return this.contains(descriptor.index, selected);33 };34 public isDisabled = (descriptor: SelectItemDescriptor): boolean => {35 return !descriptor.multiSelect && this.isGroup(descriptor);36 };37 public createDescriptorForElement = (element: SelectItemElement,38 multiSelect: boolean,39 index: number): SelectItemDescriptor => {40 const groupIndices = React.Children.map(element.props.children, ((child: SelectItemElement, row: number) => {41 return new IndexPath(row, index);42 }));43 return { multiSelect, groupIndices, index: new IndexPath(index) };44 };45 public createDescriptorForNestedElement = (element: SelectItemElement,46 descriptor: SelectItemDescriptor,47 index: number): SelectItemDescriptor => {48 return {49 ...descriptor,50 index: new IndexPath(index, descriptor.index.row),51 groupIndices: [],52 };53 };54 private createMultiSelectIndices = (descriptor: SelectItemDescriptor, selected: IndexPath[]): IndexPath[] => {55 const isIndexSelected: boolean = this.isSelected(descriptor, selected);56 return !isIndexSelected ? this.addIndex(descriptor, selected) : this.removeIndex(descriptor, selected);57 };58 private isGroup = (descriptor: SelectItemDescriptor): boolean => {59 return descriptor.groupIndices && descriptor.groupIndices.length > 0;60 };61 private createGroupIndices = (descriptor: SelectItemDescriptor): IndexPath[] => {62 return this.isGroup(descriptor) ? descriptor.groupIndices : [descriptor.index];63 };64 private addIndex = (descriptor: SelectItemDescriptor, selected: IndexPath[]): IndexPath[] => {65 return [...selected, ...this.createGroupIndices(descriptor)];66 };67 private removeIndex = (descriptor: SelectItemDescriptor, selected: IndexPath[]): IndexPath[] => {68 const groupIndices: IndexPath[] = this.createGroupIndices(descriptor);69 return selected.filter((selectedIndex: IndexPath): boolean => {70 return !this.contains(selectedIndex, groupIndices);71 });72 };73 private contains = (index: IndexPath, selected: IndexPath[]): boolean => {74 return selected.some((selectedIndex: IndexPath): boolean => {75 return selectedIndex.equals(index);76 });77 };78 private containsSomeFromGroup = (index: IndexPath, selected: IndexPath[]): boolean => {79 return selected.some((selectedIndex: IndexPath): boolean => {80 return selectedIndex.section === index.row;81 });82 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var maxProfit = require('./maxProfit');2var prices = [1, 2, 3, 4, 5, 6, 7, 8, 9];3console.log(maxProfit(prices));4module.exports = function(prices) {5 if (prices.length < 2) {6 return 0;7 }8 var maxProfit = 0;9 for (var i = 1; i < prices.length; i++) {10 if (prices[i] > prices[i - 1]) {11 maxProfit += prices[i] - prices[i - 1];12 }13 }14 return maxProfit;15};

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestFirstSearch = require('algorithms').BestFirstSearch;2var graph = new BestFirstSearch();3graph.addNode('A', {B: 1, C: 2});4graph.addNode('B', {D: 1, E: 2});5graph.addNode('C', {F: 1, G: 2});6graph.addNode('D', {H: 1, I: 2});7graph.addNode('E', {J: 1, K: 2});8graph.addNode('F', {L: 1, M: 2});9graph.addNode('G', {N: 1, O: 2});10graph.addNode('H', {P: 1, Q: 2});11graph.addNode('I', {R: 1, S: 2});12graph.addNode('J', {T: 1, U: 2});13graph.addNode('K', {V: 1, W: 2});14graph.addNode('L', {X: 1, Y: 2});15graph.addNode('M', {Z: 1, A: 2});16graph.addNode('N', {B: 1, C: 2});17graph.addNode('O', {D: 1, E: 2});18graph.addNode('P', {F: 1, G: 2});19graph.addNode('Q', {H: 1, I: 2});20graph.addNode('R', {J: 1, K: 2});21graph.addNode('S', {L: 1, M: 2});22graph.addNode('T', {N: 1, O: 2});23graph.addNode('U', {P: 1, Q: 2});24graph.addNode('V', {R: 1, S: 2});25graph.addNode('W', {T: 1, U: 2});26graph.addNode('X', {V: 1, W: 2});27graph.addNode('Y', {X: 1, Y: 2});28graph.addNode('Z', {Z: 1, A: 2});29var path = graph.indexPath('A', 'Z');30console.log(path);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestFirstSearch = require('./BestFirstSearch');2var a = new BestFirstSearch();3var graph = a.createGraph();4a.setGraph(graph);5a.setHeuristic('h');6a.setStart('S');7a.setGoal('G');8var path = a.indexPath();9console.log(path);10var AStarSearch = require('./AStarSearch');11var a = new AStarSearch();12var graph = a.createGraph();13a.setGraph(graph);14a.setHeuristic('h');15a.setStart('S');16a.setGoal('G');17var path = a.indexPath();18console.log(path);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestMatchFinder = require('./BestMatchFinder');2var fs = require('fs');3var wordsList = fs.readFileSync('words.txt', 'utf8');4wordsList = wordsList.split('5');6var bestMatchFinder = new BestMatchFinder(wordsList);7var indexPath = bestMatchFinder.indexPath('cat');8console.log(indexPath);9var BestMatchFinder = require('./BestMatchFinder');10var fs = require('fs');11var wordsList = fs.readFileSync('words.txt', 'utf8');12wordsList = wordsList.split('13');14var bestMatchFinder = new BestMatchFinder(wordsList);15var indexPath = bestMatchFinder.indexPath('cat');16console.log(indexPath);17var BestMatchFinder = require('./BestMatchFinder');18var fs = require('fs');19var wordsList = fs.readFileSync('words.txt', 'utf8');20wordsList = wordsList.split('21');22var bestMatchFinder = new BestMatchFinder(wordsList);23var indexPath = bestMatchFinder.indexPath('cat');24console.log(indexPath);25var BestMatchFinder = require('./BestMatchFinder');26var fs = require('fs');27var wordsList = fs.readFileSync('words.txt', 'utf8');28wordsList = wordsList.split('29');

Full Screen

Using AI Code Generation

copy

Full Screen

1var bp = require('./bestPath');2var g = new bp.Graph();3var n1 = new bp.Node('n1');4var n2 = new bp.Node('n2');5var n3 = new bp.Node('n3');6var n4 = new bp.Node('n4');7var n5 = new bp.Node('n5');8var n6 = new bp.Node('n6');9var n7 = new bp.Node('n7');10var n8 = new bp.Node('n8');11var n9 = new bp.Node('n9');12var n10 = new bp.Node('n10');13var n11 = new bp.Node('n11');14var n12 = new bp.Node('n12');15var n13 = new bp.Node('n13');16var n14 = new bp.Node('n14');17var n15 = new bp.Node('n15');18var n16 = new bp.Node('n16');19g.addNode(n1);20g.addNode(n2);21g.addNode(n3);22g.addNode(n4);23g.addNode(n5);24g.addNode(n6);25g.addNode(n7);26g.addNode(n8);27g.addNode(n9);28g.addNode(n10);29g.addNode(n11);30g.addNode(n12);31g.addNode(n13);32g.addNode(n14);33g.addNode(n15);34g.addNode(n16);35var e1 = new bp.Edge(n1, n2, 3);36var e2 = new bp.Edge(n1, n3, 3);37var e3 = new bp.Edge(n2, n4, 2);38var e4 = new bp.Edge(n2, n5, 4);39var e5 = new bp.Edge(n3, n6, 1);40var e6 = new bp.Edge(n3, n7, 3);41var e7 = new bp.Edge(n4, n8, 1);42var e8 = new bp.Edge(n4, n9, 2);43var e9 = new bp.Edge(n5, n10, 2);44var e10 = new bp.Edge(n5, n11, 1);45var e11 = new bp.Edge(n6, n12, 3);46var e12 = new bp.Edge(n6,

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestFit = require('bestfit');2var bf = new BestFit();3var data = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25];4var value = 12;5var index = bf.indexPath(data, value);6console.log("index: " + index);

Full Screen

Using AI Code Generation

copy

Full Screen

1var graph = require("./graph");2var BestPath = require("./BestPath");3var graph1 = new graph.Graph();4graph1.addNodes(["A","B","C","D","E","F","G","H","I"]);5graph1.addEdge("A","B",10);6graph1.addEdge("A","C",3);7graph1.addEdge("B","C",1);8graph1.addEdge("B","D",2);9graph1.addEdge("C","B",4);10graph1.addEdge("C","D",8);11graph1.addEdge("C","E",2);12graph1.addEdge("D","E",7);13graph1.addEdge("D","F",4);14graph1.addEdge("E","D",9);15graph1.addEdge("E","G",5);16graph1.addEdge("F","H",6);17graph1.addEdge("G","F",2);18graph1.addEdge("G","I",2);19graph1.addEdge("H","I",3);20var bestPath = new BestPath.BestPath(graph1);21var path = bestPath.indexPath("A","I");22console.log("Best path from A to I is: " + path);23console.log("Cost is: " + bestPath.cost);24var Graph = require("./graph").Graph;25var BestPath = function(graph) {26 this.graph = graph;27 this.cost = 0;28 this.path = [];29};30BestPath.prototype.indexPath = function(start, end) {31 var self = this;32 var path = [];33 var cost = 0;34 var paths = [];35 function findPath(node, end, path, cost) {36 path = path || [];37 cost = cost || 0;38 path.push(node);39 if (node == end) {40 paths.push({path:path, cost:cost});41 } else {42 var nodes = self.graph.adjacentNodes(node);43 for (var i = 0; i < nodes.length; i++) {44 if (path.indexOf

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful