MCPcopy Create free account
hub / github.com/cryptii/cryptii / mapElementsToSortedPosition

Method mapElementsToSortedPosition

src/Encoder/ADFGXCipher.js:204–220  ·  view source on GitHub ↗

* Maps the given elements to their corresponding positions in a sorted array. * @protected * @param {array} elements Array of elements * @return {array} Array with the corresponding position for each element

(elements)

Source from the content-addressed store, hash-verified

202 * @return {array} Array with the corresponding position for each element
203 */
204 mapElementsToSortedPosition (elements) {
205 const length = elements.length
206 const map = new Array(length)
207 const from = elements.slice()
208 const to = elements.slice().sort()
209 let index
210
211 for (let k = 0; k < length; k++) {
212 index = from.indexOf(to[k])
213 map[k] = index
214 // Flag the element as claimed, with that duplicate elements are mapped to
215 // different sorted positions
216 delete from[index]
217 }
218
219 return map
220 }
221
222 /**
223 * Triggered when a setting field has changed.

Callers 2

performEncodeMethod · 0.95
performDecodeMethod · 0.95

Calls 1

indexOfMethod · 0.80

Tested by

no test coverage detected