indexof

Lisp position of nested list element with children

偶尔善良 提交于 2020-03-05 04:35:29
问题 Say we have the following list: (A B C D) We can find the index of C with: (position 'C '(A B C D)) If, however one of the list elements is nested with its own children: (position 'B '(A (B 1 2 (3 x y z)) C D)) The function would yield NIL . How do we effectively locate the nth position of elements within a nested list like this, especially if the atom is located within a sub-list like, for example, y ? ----- Here's my attempt thus far: (setq lst (A (B 1 2 (3 x y z)) C D)) (defun top-level

How object equality checks work in Javascript? [duplicate]

丶灬走出姿态 提交于 2020-02-07 00:00:27
问题 This question already has answers here : Object comparison in JavaScript [duplicate] (10 answers) How to determine equality for two JavaScript objects? (60 answers) How to determine if Javascript array contains an object with an attribute that equals a given value? (23 answers) indexOf method in an object array? (27 answers) Closed last month . I'm trying to check for the existence of an element of an array using built-in Javascript array function const routes = [ { path: 'users/:id',

Why is indexOf not working in Internet Explorer?

倖福魔咒の 提交于 2020-02-02 03:05:26
问题 This function executes during the forms onSubmit, and works fine in Firefox and Chrome, but not in IE. I suspect it's indexOf, but I cannot seem to find a way to get it to work. function checkSuburbMatch(e) { var theSuburb = document.getElementById('suburb').value; var thePostcode = document.getElementById('postcode').value; var arrayNeedle = theSuburb + " (" + thePostcode + ")"; if(suburbs.indexOf(arrayNeedle) != -1) { alert("Suburb and Postcode match!"); return false; } else { alert("Suburb

Removing a collection of custom types from a Swift Array

那年仲夏 提交于 2020-01-25 08:23:07
问题 I've created a Swift array that contains collections of two instances of a custom data type: var myArray : [(MyDataType, MyDataType)]! When I want to add items to this array, it's trivial to do so with the following code (where firstVar and secondVar are instances of MyDataType ) myArray.append((firstVar, secondVar)) What I'm currently struggling with is removing items from myArray . Using this code, I get an error of Value of type '[(MyDataType, MyDataType)]' has no member 'indexOf' : let

return index of the first letter of a specific substring of a string

北战南征 提交于 2020-01-16 01:28:25
问题 I am given a string and I wish to find out the index of the first character of a substring of that string whenever it appears the very first time in the parent string. For example, given a string "itiswhatitis" and the substring "is", the output should be 2. 回答1: You can use as below int indexOf(String str) from your example string. String s ="itiswhatitis"; int index = s.indexOf("is"); 回答2: "itiswhatitis".indexOf("is") Try this 回答3: public static void main(String[] args) { int index =

Find byte sequence within a byte array

隐身守侯 提交于 2020-01-12 07:50:34
问题 I have a byte array and wish to find the "occurrences" of some bytes. For example 00 69 73 6F 6D in a very large byte array (> 50/100 Megabytes) OR even better a reverse operation: Searching the most common pattern without knowing it the code should be able to read and find it from the file. 回答1: You can use the Boyer-Moore algorithm to efficiently search for a sequence of bytes in an array of bytes. Here's a C# version I converted from the Java version from the Wikipedia entry on Boyer-Moore

What is a Unicode safe replica of String.IndexOf(string input) that can handle Surrogate Pairs?

孤街醉人 提交于 2020-01-11 11:51:11
问题 I am trying to figure out an equivalent to C# string.IndexOf(string) that can handle surrogate pairs in Unicode characters. I am able to get the index when only comparing single characters, like in the code below: public static int UnicodeIndexOf(this string input, string find) { return input.ToTextElements().ToList().IndexOf(find); } public static IEnumerable<string> ToTextElements(this string input) { var e = StringInfo.GetTextElementEnumerator(input); while (e.MoveNext()) { yield return e

What is a Unicode safe replica of String.IndexOf(string input) that can handle Surrogate Pairs?

无人久伴 提交于 2020-01-11 11:50:08
问题 I am trying to figure out an equivalent to C# string.IndexOf(string) that can handle surrogate pairs in Unicode characters. I am able to get the index when only comparing single characters, like in the code below: public static int UnicodeIndexOf(this string input, string find) { return input.ToTextElements().ToList().IndexOf(find); } public static IEnumerable<string> ToTextElements(this string input) { var e = StringInfo.GetTextElementEnumerator(input); while (e.MoveNext()) { yield return e

Search for all instances of a string inside a string

谁说我不能喝 提交于 2020-01-09 19:48:08
问题 Hello I am using indexOf method to search if a string is present inside another string. But I want to get all the locations of where string is? Is there any method to get all the locations where the string exists? <html> <head> <script type="text/javascript"> function clik() { var x='hit'; //document.getElementById('hideme').value =''; document.getElementById('hideme').value += x; alert(document.getElementById('hideme').value); } function getIndex() { var z =document.getElementById('hideme')

Is there an indexOf in javascript to search an array with custom compare function

南楼画角 提交于 2020-01-09 07:12:09
问题 I need the index of the first value in the array, that matches a custom compare function. The very nice underscorej has a "find" function that returns the first value where a function returns true, but I would need this that returns the index instead. Is there a version of indexOf available somewhere, where I can pass a function used to comparing? Thanks for any suggestions! 来源: https://stackoverflow.com/questions/12356642/is-there-an-indexof-in-javascript-to-search-an-array-with-custom