1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.gen.js: add more array tests and fixes (#11014)

This commit is contained in:
playX
2021-08-01 14:08:49 +03:00
committed by GitHub
parent 77e9ed417f
commit 836ac54d12
8 changed files with 356 additions and 15 deletions

View File

@ -87,8 +87,21 @@ pub fn (mut a array) sort_with_compare(compare voidptr) {
#a.arr.sort(compare)
}
#function $sortComparator(a, b)
#{
#"use strict";
#a = a.$toJS();
#b = b.$toJS();
#
#if (a > b) return 1;
#if (a < b) return -1;
#return 0;
#
#
#}
pub fn (mut a array) sort() {
#a.arr.sort()
#a.arr.sort($sortComparator)
}
pub fn (a array) index(v string) int {
@ -137,7 +150,7 @@ pub fn (a array) str() string {
#array.prototype[Symbol.iterator] = function () { return this.arr[Symbol.iterator](); }
#array.prototype.entries = function () { return this.arr.entries(); }
#array.prototype.map = function(callback) { return this.arr.map(callback); }
#array.prototype.map = function(callback) { return new builtin.array(this.arr.map(callback)); }
#array.prototype.filter = function(callback) { return new array(this.arr.filter( function (it) { return (+callback(it)) != 0; } )); }
#Object.defineProperty(array.prototype,'cap',{ get: function () { return this.len; } })
// delete deletes array element at index `i`.