time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

main.js (1653B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MODULES //
     22 
     23 var propertyNames = require( './../../property-names' );
     24 var propertySymbols = require( './../../property-symbols' );
     25 var isWritable = require( '@stdlib/assert/is-writable-property' );
     26 
     27 
     28 // MAIN //
     29 
     30 /**
     31 * Returns an array of an object's own writable property names and symbols.
     32 *
     33 * @param {*} value - input object
     34 * @returns {Array} a list of own property writable names and symbols
     35 *
     36 * @example
     37 * var obj = {
     38 *     'beep': 'boop',
     39 *     'foo': 3.14
     40 * };
     41 *
     42 * var props = writableProperties( obj );
     43 * // e.g., returns [ 'beep', 'foo' ]
     44 */
     45 function writableProperties( value ) {
     46 	var out;
     47 	var tmp;
     48 	var n;
     49 	var i;
     50 
     51 	out = propertyNames( value );
     52 	n = 0;
     53 	for ( i = 0; i < out.length; i++ ) {
     54 		if ( isWritable( value, out[ i ] ) ) {
     55 			out[ n ] = out[ i ];
     56 			n += 1;
     57 		}
     58 	}
     59 	out.length = n;
     60 
     61 	tmp = propertySymbols( value );
     62 	for ( i = 0; i < tmp.length; i++ ) {
     63 		if ( isWritable( value, tmp[ i ] ) ) {
     64 			out.push( tmp[ i ] );
     65 		}
     66 	}
     67 	return out;
     68 }
     69 
     70 
     71 // EXPORTS //
     72 
     73 module.exports = writableProperties;